Hi Martin, I'm not sure about the wrapper, and because it is an old wrapper,
there is no help pages for it and it no longer gets updated as there is now
a version for 2.0

My deadline is the end of the month for the project, but I also have to make
time to do my dissertation.

I think I am nearly there, I can get the combo box filled with the first
field name, it just doesnt fill the rest in, as it doesnt know how many
times to go through the loop.

My code is as follows :-

Private Sub frmCreateIndex_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
       Dim i As Integer
Dim a As Integer
       Dim tableSelected As String
       tableSelected = cmbTableIndex.SelectedItem
       Try
           'dbConn.selectFieldNames("pragma table_info(" & tableSelected &
")")
           dbConn.selectFieldNames("pragma table_info(test)")
           For a = 0 To UBound(dbConn.fieldNames)
               cmbFieldIndex.Items.Add(dbConn.fieldNames(a))
           Next a
       Catch es As Exception
           MessageBox.Show(es.Message)
End Try
End Sub

Public Function selectFieldNames(ByVal strSQL As String) As Array
       Dim fields As Integer
       ' select all total of all tables from the sqlite master table
       sqlite_cmd.CommandText = (strSQL)
       fields = sqlite_cmd.ExecuteScalar()

       ReDim fieldNames(fields)
       ' 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")
           Catch es As Exception
               MessageBox.Show(es.Message)
           End Try
           i += 1
       End While
       sqlite_datareader.Close()
      Return fieldNames
   End Function

On 13/07/06, Martin Jenkins <[EMAIL PROTECTED]> wrote:

John Newby wrote:
> I would still need to know how many times to go through the while
> loop to add the names of the fields?

John,

I haven't been following this thread that closely, but (based on other
wrappers I've used) I would have expected your sqlite wrapper to do one
of two things:

a) let you request all results returned in an array or list
b) let you request results one at a time and raise an error or exception
    when you've run off the end.

In a) you don't need to know the number of results or allocate an array
to hold them - the wrapper does it for you. If you use the right query
you get what you want with no work.

In b) you start with an empty list or array and loop through the result
set appending each result to the end of the list. Dictionaries solve the
know-the-size-in-advance problem but aren't really appropriate as you
lose the order of the fields and you have to extract the keys/names (and
store them...?) before you can use them.

You only need a while loop for b) because if you know the number of
items in advance a for-loop would be more appropriate. a) is the better
solution here because it's less work on your part.

It's a pity you're stuck with VB - what you're trying to do is a one
liner in Python with either of apsw or pysqlite and I imagine most other
languages and wrappers are similar. :-/

JOOI, when is your deadline?

Martin

Reply via email to