[sqlite] C++ programming - SELECT question
A pessimist is one who makes difficulties of his opportunities and an optimist is one who makes opportunities of his difficulties. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - SELECT question
Arbol One arbol...@gmail.com wrote: A pessimist is one who makes difficulties of his opportunities and an optimist is one who makes opportunities of his difficulties. Is there a question in there somewhere? -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] C++ programming - getting data from a table
in a database called 'db' I created a table named 'friend' that looks like this: string create_table( CREATE TABLE friend (name TEXT, address TEXT, age INT)); I entered some values in that table and now I would like to extract the values from that table. Shown below is what I have done so far, but I have hit a wall, I cannot find definitive information as to how to view the extracted data, if any. What do I do next to view the data from that table? TIA snip getData(){ string sName; string sAddress; int age = 0; string dbdata = SELECT * FROM friend; rc = sqlite3_prepare_v2( db, /* Database handle */ dbdata.c_str() , /* SQL statement, UTF-8 encoded */ dbdata.length(), /* Maximum length of zSql in bytes. */ stmt,/* OUT: Statement handle */ NULL /* OUT: Pointer to unused portion of zSql */ ); rc = sqlite3_step(stmt); ? } A pessimist is one who makes difficulties of his opportunities and an optimist is one who makes opportunities of his difficulties. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - getting data from a table
On 24 Jun 2012, at 3:40pm, Arbol One arbol...@gmail.com wrote: I entered some values in that table and now I would like to extract the values from that table. Shown below is what I have done so far, but I have hit a wall, I cannot find definitive information as to how to view the extracted data, if any. What do I do next to view the data from that table? [Simplified answer for SQLite starter] You're asking about the set of commands which go _prepare(), _step(), _finalize(). These are commands which create, use and destroy an SQLite statement. Do one _prepare() which causes SQLite to do complicated things to make a statement. Do _step() to get a row, and continue to do them while it continues to give a result code of SQLITE_ROW Do one _finalize() to tell SQLite you no longer need that statement's handle, memory, etc.. If _step() returns SQLITE_ROW it makes available one row of the resulting table. You can read the data from that row using functions like sqlite3_column_int() and sqlite3_column_text(). You need as many of these calls as you expect columns returned by your SELECT statement. You pass into that function the statement handle, and the number of the column you want, with column 0 being the first column. Details of the statement loop are here: http://www.sqlite.org/c3ref/stmt.html Details of how to retrieve the values of a row are here: http://www.sqlite.org/c3ref/column_blob.html Hope this helps. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - getting data from a table
' view the extracted data ' Thank you for the prompt response. Now, using simple std::cout, could you show (give an example) of how to display (out streaming) the data extracted? Thanks! Note to developers ~~ The C/C++ documentation of SQLite must include small examples. TIA -Original Message- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Simon Slavin Sent: Sunday, June 24, 2012 11:59 AM To: General Discussion of SQLite Database Subject: Re: [sqlite] C++ programming - getting data from a table On 24 Jun 2012, at 3:40pm, Arbol One arbol...@gmail.com wrote: I entered some values in that table and now I would like to extract the values from that table. Shown below is what I have done so far, but I have hit a wall, I cannot find definitive information as to how to view the extracted data, if any. What do I do next to view the data from that table? [Simplified answer for SQLite starter] You're asking about the set of commands which go _prepare(), _step(), _finalize(). These are commands which create, use and destroy an SQLite statement. Do one _prepare() which causes SQLite to do complicated things to make a statement. Do _step() to get a row, and continue to do them while it continues to give a result code of SQLITE_ROW Do one _finalize() to tell SQLite you no longer need that statement's handle, memory, etc.. If _step() returns SQLITE_ROW it makes available one row of the resulting table. You can read the data from that row using functions like sqlite3_column_int() and sqlite3_column_text(). You need as many of these calls as you expect columns returned by your SELECT statement. You pass into that function the statement handle, and the number of the column you want, with column 0 being the first column. Details of the statement loop are here: http://www.sqlite.org/c3ref/stmt.html Details of how to retrieve the values of a row are here: http://www.sqlite.org/c3ref/column_blob.html Hope this helps. Simon. ___ 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
Re: [sqlite] C++ programming - getting data from a table
On 24 Jun 2012, at 5:31pm, Arbol One arbol...@gmail.com wrote: Thank you for the prompt response. Now, using simple std::cout, could you show (give an example) of how to display (out streaming) the data extracted? Someone else perhaps. I don't use C++. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - getting data from a table
Arbol One arbol...@gmail.com wrote: Thank you for the prompt response. Now, using simple std::cout, could you show (give an example) of how to display (out streaming) the data extracted? sqlite3* db; sqlite3_open(db, db); sqlite_stmt* stmt; sqlite3_prepare_v2(db, select name, address, age from friend, -1, stmt, NULL); while (sqlite3_step(stmt) == SQLITE_ROW) { cout (char*)sqlite3_column_text(stmt, 0) ' ' (char*)sqlite3_column_text(stmt, 1) ' ' sqlite3_column_int(stmt, 2) endl; } sqlite3_finalize(stmt); sqlite3_close(db); Error handling is left as an exercise for the reader. -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - getting data from a table
Nice!! I will try your explanation in my test-bench, but just by looking at it, it make sense. Thanks Igor!! -Original Message- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Igor Tandetnik Sent: Sunday, June 24, 2012 12:55 PM To: sqlite-users@sqlite.org Subject: Re: [sqlite] C++ programming - getting data from a table Arbol One arbol...@gmail.com wrote: Thank you for the prompt response. Now, using simple std::cout, could you show (give an example) of how to display (out streaming) the data extracted? sqlite3* db; sqlite3_open(db, db); sqlite_stmt* stmt; sqlite3_prepare_v2(db, select name, address, age from friend, -1, stmt, NULL); while (sqlite3_step(stmt) == SQLITE_ROW) { cout (char*)sqlite3_column_text(stmt, 0) ' ' (char*)sqlite3_column_text(stmt, 1) ' ' sqlite3_column_int(stmt, 2) endl; } sqlite3_finalize(stmt); sqlite3_close(db); Error handling is left as an exercise for the reader. -- Igor Tandetnik ___ 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
[sqlite] MyJSQLView Version 3.35 Release
MyJSQLView Version 3.35 Released The MyJSQLView project is pleased to release v3.35 to the public. The release is a maintenance update to address several issues that manifest themselves when using the SQL Query Bucket and Query Frame. Drops to the Query Bucket from the main summary table fail to properly create the syntax as derived from the search and sort parameters in the Summary Table. Fixes to the Query Frame now allow the use of aliases. The application has also been updated to remove legacy data structures that had decrease the efficiency of the application. Dana M. Proctor MyJSQLView Project Manager http://dandymadeproductions.com/projects/MyJSQLView/ http://www.xerial.org/trac/Xerial MyJSQLView provides an easy to use free open source Java based user interface frontend for viewing, adding, editing, or deleting entries in several mainstream databases. A query frame allows the building of complex SQL statements and a SQL Query Bucket for saving such. The application allows easy sorting, searching, and import/export of table data. A plug-in framework has allowed the inclusion of tools to profile and plot data for analysis. MyJSQLView uses the Xerial JDBC driver to communication with the SQLite database files. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - creating a table
Arbol One arbol...@gmail.com wrote: create_table = CREATE TABLE friend (name TEXT, address TEXT, age INT); std::cout sqlite3_column_type(stmt,0) std::endl; sqlite_column_* functions are only meaningful for queries that produce a resultset - namely, SELECT and certain PRAGMAs. None of the data definition statements (of which CREATE TABLE is one), nor INSERT, UPDATE or DELETE statements, produce a resultset; thus, sqlite3_column_* functions couldn't be used with them. What are you trying to achieve here? What's the supposed purpose of sqlite3_column_type call? -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] C++ programming - inserting data in a table
Thanks for the prompt response. Here is the same problem when using INSERT. Setter() { dbdata = INSERT INTO friend VALUES('Caramba', '490 New Bridge', '49'); rc = sqlite3_prepare_v2( db, dbdata.c_str() , dbdata.length(), stmt, NULL ); . rc = sqlite3_step(stmt); if(rc != SQLITE_DONE) { .. } /// the output here is 5, meaning SQLITE_NULL. The output should be 3 = SQLITE3_TEXT std::cout sqlite3_column_type(stmt,0); sqlite3_finalize(stmt); } -Original Message- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Igor Tandetnik Sent: Monday, June 25, 2012 12:07 AM To: sqlite-users@sqlite.org Subject: Re: [sqlite] C++ programming - creating a table Arbol One arbol...@gmail.com wrote: create_table = CREATE TABLE friend (name TEXT, address TEXT, age INT); std::cout sqlite3_column_type(stmt,0) std::endl; sqlite_column_* functions are only meaningful for queries that produce a resultset - namely, SELECT and certain PRAGMAs. None of the data definition statements (of which CREATE TABLE is one), nor INSERT, UPDATE or DELETE statements, produce a resultset; thus, sqlite3_column_* functions couldn't be used with them. What are you trying to achieve here? What's the supposed purpose of sqlite3_column_type call? -- Igor Tandetnik ___ 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
Re: [sqlite] C++ programming - inserting data in a table
Arbol One arbol...@gmail.com wrote: Thanks for the prompt response. Here is the same problem when using INSERT. Which part of INSERT ... statement [doesn't] produce a resultset; thus, sqlite3_column_* functions couldn't be used with [it] do you have difficulty understanding? -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users