Hi Kees, I'm writing it in VB.Net 2002.

I think I've got somethign nearly working now, but I need to somehow get a
count of how many fields is in the table, or how many rows the pragma
command brings back so that I can give the array a number before I can fill
it.  Does anyone know the name of the first column returned in the pragma
table_info(test) command, it looks as if its counting the rows(fields),
maybe I could use this somehow.

The code Ive got so far is as follows :

Public Function selectFieldNames(ByVal strSQL As String) As Array

       ' select all field names from the selected table
       sqlite_cmd.CommandText = (strSQL)
       ' Now the SQLiteCommand object can give us a DataReader-Object:
       sqlite_datareader = sqlite_cmd.ExecuteReader()
       i = 0
       While sqlite_datareader.Read()
           'Try
           fieldNames(i) = sqlite_datareader("name")
           'atch es As Exception
           '  MessageBox.Show(es.Message)
           End Try
           i += 1
       End While

       sqlite_datareader.Close()

       Return fieldNames
   End Function

On 12/07/06, Kees Nuyt <[EMAIL PROTECTED]> wrote:

On Wed, 12 Jul 2006 19:05:51 +0100, you wrote:

> Hi, how can I find out the names of the
> fields within a given table?
>
> I've tried "pragma table_info(test);"
> but this brings back too much info,
> I just require the names as I'll be
> storing them in an array within my application.

Your application could select the 'name' column in your result
set.
In what language is your application written?
PHP for example has a nice wrapper to achieve what you want:

        sqlite_array_query()

Here is some sample PHP code (wrapped by mailclient):

        if ($dbhandle = sqlite_open($dbfilename, 0666,
$sqliteerror)){
// query
                $result = sqlite_array_query($dbhandle, 'SELECT * FROM
tablename', SQLITE_ASSOC);
// display
                printf('<table>');
                $firsttime = TRUE;
                foreach ($aResult as $aRow){
                        if ($firsttime){
                                printf('<tr>');
                                foreach ($aRow as $col => $val){
                                        printf('<th>%s</th>',$col);
                                }
                                reset($aRow);
                                printf("</tr>\n");
                                $firsttime = FALSE;
                        }
                        printf('<tr>');
                        foreach ($aRow as $col => $val){
                                printf('<td>%s</td>',$val);
                        }
                        printf("</tr>\n");
                }
                printf('</table>');
                sqlite_close($dbhandle);
        } else {
                die($sqliteerror);
        }


>Many thanks
>
>John

Hope this helps.
--
kees

Reply via email to