setup() must be some other function in the book.  Get rid of it.  Probably runs 
some pragmas.



You can force the name error to go away by casting to char *.



Or you can strdup the sqlite3_column_text value and free it when you're done.



The error is warning you that you need to be aware that this value is not 
permanent.



You'll also need to rename the function to int main() -- otherwise it won't 
link.







Michael D. Black

Senior Scientist

Advanced Analytics Directorate

Advanced GEOINT Solutions Operating Unit

Northrop Grumman Information Systems

________________________________
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of deltagam...@gmx.net [deltagam...@gmx.net]
Sent: Wednesday, June 20, 2012 10:04 AM
To: General Discussion of SQLite Database
Subject: EXT :Re: [sqlite] How to select from table

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
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to