Hi all,
I am trying to understand Sqlite and to make thing worse I am also learning C++. You will not be surprised that I find it really hard to understand the C++ example on the web. Can someone guide me to digest this? If you can explain please do so by extrapolating since I am a total newbie. I have managed to compile the code example into a file called testdb.exe and have created a database named Cars.db containing 7 rows. (notice that I have removed some part of that code that I don't need help for) #include <stdio.h> #include <sqlite3.h> static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; for(i=0; i<argc; i++){ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0; } int main(int argc, char **argv){ sqlite3 *db; char *zErrMsg = 0; int rc; if( argc!=3 ){ fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); exit(1); } rc = sqlite3_open(argv[1], &db); rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg); sqlite3_close(db); return 0; } Now in command line when I execute testdb.exe cars.db "select * from cars" (the table is called cars too) everything works fine and I get an output with all my seven rows. But how come this work? Is this some kind of magic? Even after reading the doc again and again I don't understand (probably because I am still learning some basic C++ concepts). Here my questions; 1) What is the purpose of doing "sqlite3 *db" are we just creating a pointer of type sqlite3 named db here? 2) At first I though that for the main function the first parameter "cars.db" was represented by the variable argc and the second "select * from cars" by argv. Well at the end, it looks like that "cars.db" is argv[1] and that the select statement is argv[2]. What is argc then? Seems like it's the number of rows returned by the query (when looking at function callback) but how the program find this out? How come we have a line " if( argc!=3 )" and see this same argc variable in the callback function? 3) I don't understand the third argument from the query " rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);" my problem is understanding the callback function inside the sqlite3_exec function. Reading this link http://www.sqlite.org/c3ref/exec.html didn't help too much even though it has been written in plain English. 4) I am using VC++ Express from Microsoft on WinXP and would like to know if it's possible to pass parameter when debugging i.e. tell the debugger to use cars.db for file and use "select * from cars" as a statement (this would allow me to see what's hapening witout replacing variables by their real values). 5) It's really hard to find some simple example on internet about C++ working with sqlite. Can any of you provide with simple sample codes that shows how you can do and what you can do with sqlite and C++? I hope I didn't offended anyone with my lack of knowledge and I thank in advance the courageous ones who managed to read this email until the end and probably got answers to my questions. Fabou _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users