Am 20.06.2012 14:55, schrieb Igor Tandetnik:
deltagam...@gmx.net wrote:
how can i select from sqlite3 db ?
By executing a SELECT statement, of course. See this example:

http://books.google.com/books?id=VsZ5bUh0XAkC&pg=PA222

How do I retrieve the number of records in a table ?
By running this statement: select count(*) from MyTable;

thx for the hint, it is an interesting book, but in the example on page 222
I get 2 errors

....  select_all_from_db.cpp(23): error C3861: 'setup': identifier not found
.... select_all_from_db.cpp(41): error C2440: '=' : cannot convert from 'const unsigned char *' to 'char *'
line 41 is :   name = sqlite3_column_text(stmt, 2 );

I checked on the documentation side http://sqlite.org/capi3ref.html , there is nothing about setup ...
And what is the problem with name ?


==============================================================
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

#include <ctime>
#include <iostream>
#include <string>
#include <fstream>

using namespace std;


void select_all_rows_db() {

    int rc, i, ncols, id, cid;
    char *name, *sql;
    sqlite3 *db;
    sqlite3_stmt *stmt;

    sql = "Select ID, EVENTTYPE FROM eventlog";
    sqlite3_open("ah.db", &db);

    setup(db);

    sqlite3_prepare(db, sql, strlen(sql), &stmt, NULL);
    rc = sqlite3_step(stmt);

/*Print column information */
for (i=0; i< ncols; i++ ) {
    fprintf(stdout, "Column: name=%s, storage class=%i, declared=%s\n",
                sqlite3_column_name(stmt, i ),
                sqlite3_column_type(stmt, i ),
                sqlite3_column_decltype(stmt, i ));
} // for

fprintf(stdout, "\n");

while(rc == SQLITE_ROW) {
    id = sqlite3_column_int(stmt, 0 );
    cid = sqlite3_column_int(stmt, 1 );
    name = sqlite3_column_text(stmt, 2 );

    if (name != NULL ) {
        fprintf(stderr, "Row: id=%i, cid=%i, name='%s'\n", id, cid, name);
    } else {
        /* Field is NULL */
        fprintf(stderr, "Row: id=%i, cid=%i, name=NULL\n", id, cid);
    }
    rc = sqlite3_step(stmt);
} // while

sqlite3_finalize(stmt);
sqlite3_close(db);


} // select_all_rows_db
====================================================================

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to