/* _______ __ __ __ __ \ \ ____ __ __ _______ |__|| | | | |__| ____ ____ / | \ _/ __ \ | | \\_ __ \| || | | | | | / _ \ / \ / | \\ ___/ | | / | | \/| || |__| |__| |( <_> )| | \ \____|__ / \___ >|____/ |__| |__||____/|____/|__| \____/ |___| / =========\/======\/=================================================\/== v0.01 03/AUG/2007 (C) Copyright 2007-2007 Scott D. Yelich SOME RIGHTS RESERVED .,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.-*~'`^`'~*-,._.,-*~'`^`'~*-,. LICENSE: Creative Commons Attribution 3.0 License. SEE: http://creativecommons.org/licenses/by/3.0/ Mon Aug 13 23:19:12 EDT 2007, v0.01 sdy This is a *very* simple program written to do test basic sqlite3 functionality. */ // C++ #include #include #include // LOCAL #include "Xql3.h" // Sqlite3 int main() { // (1) Basically, the program/object would have an init or open method: // The variable is declared (and constructed) outside of the try block // so that it may be referenced in the scope of the catch ... Xql3 sql3; try { sql3.open("./data.db"); // Using default callback of Xql3 ... } catch (Xql3Exception & e) { std::cerr << "sqlite3_error: " << sql3.dberrcode() << " --> " << sql3.dberrmsg() << std::endl; std::cerr << "Xql3Exception: " << e.code() << " --> " << e.what() << std::endl; return 1; // exit with error .... } // prepare an SQL std::string ... std::stringstream sql_command_ss; sql_command_ss.str(""); sql_command_ss << "DROP TABLE IF EXISTS simple_v1a;"; sql_command_ss << "CREATE TABLE simple_v1a (text,int,time);"; sql_command_ss << "INSERT INTO simple_v1a VALUES('sample v1a text1',1,DATETIME('NOW'));"; sql_command_ss << "UPDATE simple_v1a SET int=int+1 where text='sample v1a text1';"; sql_command_ss << "INSERT INTO simple_v1a VALUES('sample v1a text2',2,DATETIME('NOW'));"; sql_command_ss << "SELECT rowid,* FROM simple_v1a WHERE int<500;"; // (2) Also, the program/object would have an "exec" method ... try { sql3.exec(sql_command_ss.str()); } catch (Xql3Exception & e) { std::cerr << "sqlite3_error: " << sql3.dberrcode() << " --> " << sql3.dberrmsg() << std::endl; std::cerr << "Xql3Exception: " << e.code() << " --> " << e.what() << std::endl; return 1; // exit with error .... } // display results, access the public vectors of strings // directly from the Xql3 class object: int header_count = sql3._headers.size(); if ( header_count > 0 ) { int i; char sep = '|'; for(i=0; i