How to get COUNT(*) working?

Nov 2, 2011 at 1:48 PM

Hello,

Just downloaded the library to connect my Excel project with SQLLite. I'm a newbie with SQL, but need the number of records from a table to dimension an array. If I use "SQLite3PrepareV2(myDbHandle, "SELECT COUNT(*) FROM Project", myStmtHandle)" my return value is "1". How can I put the result of "COUNT" in a variable?

Thanks in Advance,

Henk

Coordinator
Nov 2, 2011 at 2:16 PM

Hi Henk,

After doing the query you'd use SQLite3ColumnInt32(stmtHandle, 0) to retrieve the value of the first column in the results - in this case the Count.

-Govert

Nov 2, 2011 at 2:17 PM

Thank you, for your fast response!

Nov 2, 2011 at 2:35 PM

Govert,

Every table I use gives a result of 0!

    RetVal = SQLite3PrepareV2(myDbHandle, "SELECT COUNT(*) FROM project", myStmtHandle)
    Debug.Print "SQLite3PrepareV2 returned " & RetVal     (Result 0)
   
    iNumRecords = SQLite3ColumnInt32(myStmtHandle, 0)
    Debug.Print "SQLite3ColumnInt32 returned " & iNumRecords    (Result 0, must be 7)

Do you have a hint?

Coordinator
Nov 2, 2011 at 2:38 PM

Hi Henk,

After prepare, you need to call SQLite3Step to actually execute the query and place you on the first result row - see the documentation here: http://www.sqlite.org/c3ref/step.html.

-Govert