• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            流量統(tǒng)計:
            Rixu Blog (日需博客)
            日需博客,每日必需來踩踩哦..
            posts - 108,comments - 54,trackbacks - 0
            Here you can see some examples.
            It shows a part of the functionality of the wrapper and how you can use it.
            You can find more examples in the example application (contained in download package). 


            1. open a database and create a statement instance for sql queries/statements
            1. // open database
            2. Kompex::SQLiteDatabase *pDatabase = new Kompex::SQLiteDatabase("test.db", SQLITE_OPEN_READWRITE, 0);
            3. // create statement instance for sql queries/statements
            4. Kompex::SQLiteStatement *pStmt = new Kompex::SQLiteStatement(pDatabase);


            2. create a new table and fill it with data
            1. // create table and insert some data
            2. pStmt->SqlStatement("CREATE TABLE user                        \
            3.                     (                                         \
            4.                     userID INTEGER NOT NULL PRIMARY KEY,      \
            5.                     lastName VARCHAR(50) NOT NULL,            \
            6.                     firstName VARCHAR(50), age INTEGER        \
            7.                     )");
            8.                     
            9. pStmt->SqlStatement("INSERT INTO user (userID, lastName, firstName, age) \
            10.                      VALUES (1, 'Lehmann', 'Jamie', 20)");
            11. pStmt->SqlStatement("INSERT INTO user (userID, lastName, firstName, age) \
            12.                      VALUES (2, 'Burgdorf', 'Peter', 55)");
            13. pStmt->SqlStatement("INSERT INTO user (userID, lastName, firstName, age) \
            14.                      VALUES (3, 'Lehmann', 'Fernando', 18)");
            15. pStmt->SqlStatement("INSERT INTO user (userID, lastName, firstName, age) \
            16.                      VALUES (4, 'Lehmann', 'Carlene', 17)");


            3. use some aggregate functions
            1. pStmt->SqlAggregateFuncResult("SELECT COUNT(*) FROM user WHERE lastName = 'Lehmann';");
            2. pStmt->SqlAggregateFuncResult("SELECT COUNT(weight) FROM user;");
            3. pStmt->SqlAggregateFuncResult("SELECT MAX(age) FROM user;");
            4. pStmt->SqlAggregateFuncResult("SELECT MIN(age) FROM user;");
            5. pStmt->SqlAggregateFuncResult("SELECT AVG(age) FROM user;");
            6. pStmt->SqlAggregateFuncResult("SELECT SUM(age) FROM user;");
            7. pStmt->SqlAggregateFuncResult("SELECT TOTAL(age) FROM user;");


            4. execute and process a sql query
            1. pStmt->Sql("SELECT * FROM user WHERE firstName = 'Jamie';");
            2. // process all results
            3. while(pStmt->FetchRow())
            4. {
            5.     std::cout << "first name: " << pStmt->GetColumnInt(0) << std::endl;
            6.     std::cout << "last name: " << pStmt->GetColumnString(1) << std::endl;
            7.     std::cout << "first name: " << pStmt->GetColumnString(2) << std::endl;
            8. }
            9. // do not forget to clean-up
            10. pStmt->FreeQuery();


            5. execute a simple transaction
            1. // if an error occurs, a rollback is automatically performed
            2. pStmt->BeginTransaction();
            3. pStmt->Transaction("INSERT INTO user(userID, firstName, age) VALUES (10, 'Makoto', 23)");
            4. pStmt->Transaction("INSERT INTO user(userID, firstName, age) VALUES (11, 'Yura', 20)";
            5. pStmt->Transaction("INSERT INTO user(userID, firstName, age) VALUES (12, 'Peter', 63)");
            6. pStmt->CommitTransaction();


            6. here you can see the exception handling
            1. try
            2. {
            3.     // table structure: userID INTEGER NOT NULL PRIMARY KEY, lastName VARCHAR(50)
            4.     pStmt->SqlStatement("INSERT INTO user(userID, lastName) VALUES(1, 'Lehmann')");
            5.     // the following line will throw an exception because the primary key is not unique
            6.     pStmt->SqlStatement("INSERT INTO user(userID, lastName) VALUES(1, 'Bergmann')");
            7. }
            8. catch(Kompex::SQLiteException &exception)
            9. {
            10.     std::cerr << "Exception Occured" << std::endl;
            11.     exception.Show();
            12. }


            7. work with a memory database
            1. Kompex::SQLiteDatabase *pDatabase = new Kompex::SQLiteDatabase("scores.db", SQLITE_OPEN_READWRITE, 0);
            2. // move database to memory, so that we are work on the memory database hence
            3. pDatabase->MoveDatabaseToMemory();
            4.  
            5. Kompex::SQLiteStatement *pStmt = new Kompex::SQLiteStatement(pDatabase);
            6. // insert some data sets into the memory database
            7. pStmt->SqlStatement("INSERT INTO score(id, lastScore, avgScore) VALUES(1, 429, 341)");
            8. pStmt->SqlStatement("INSERT INTO score(id, lastScore, avgScore) VALUES(2, 37, 44)");
            9. pStmt->SqlStatement("INSERT INTO score(id, lastScore, avgScore) VALUES(3, 310, 280)");
            10.  
            11. // save the memory database to a file
            12. // if you don't do it, all database changes will be lost after closing the memory database
            13. pDatabase->SaveDatabaseFromMemoryToFile("newScores.db");


            8. get some result values via column name (more flexible and a little bit slower than the common way)
            1. pStmt->Sql("SELECT * FROM user WHERE lastName = 'Lehmann';");
            2.  
            3. // process all results
            4. while(pStmt->FetchRow())
            5. {
            6.     std::cout << "firstName: " << pStmt->GetColumnString("firstName") << std::endl;
            7.     std::cout << "age: " << pStmt->GetColumnInt("age") << std::endl;
            8. }
            9.  
            10. // do not forget to clean-up
            11. pStmt->FreeQuery();    


            9. two possibilities to update data in the database
            1. // the first way
            2. pStmt->SqlStatement("UPDATE user SET weight=51.5, age=18 WHERE firstName='Carlene'");
            3.         
            4. // the second way - with a prepared statement
            5. pStmt->Sql("UPDATE user SET lastName=@lastName, age=@age WHERE userID=@userID");
            6.             
            7. // bind an integer to the prepared statement
            8. pStmt->BindString(1, "Urushihara");        // bind lastName
            9. pStmt->BindInt(2, 56);                    // bind age
            10. pStmt->BindInt(3, 2);                    // bind userID
            11.  
            12. // execute it and clean-up
            13. pStmt->ExecuteAndFree();
            Logo
            作者:Gezidan
            出處:http://www.rixu.net    
            本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權(quán)利。
            posted on 2011-08-02 14:12 日需博客 閱讀(1736) 評論(1)  編輯 收藏 引用 所屬分類: C C++技術文章轉(zhuǎn)載

            FeedBack:
            # re: Kompex SQLite Wrapper for C++ - Examples
            2012-09-21 18:09 | czp
            你把別網(wǎng)站上的代碼拷貝過來,有意思嗎?  回復  更多評論
              
            国产99精品久久| 久久婷婷五月综合色奶水99啪| 久久亚洲精品无码VA大香大香| 亚洲精品国产综合久久一线| 久久久久久久波多野结衣高潮 | 久久婷婷综合中文字幕| 久久99精品国产99久久| 久久精品国产精品亚洲| 日产精品99久久久久久| 激情久久久久久久久久| 一极黄色视频久久网站| 精品久久久久久久| 99久久国产亚洲综合精品| 国产午夜精品理论片久久影视| 香蕉久久久久久狠狠色| 丰满少妇人妻久久久久久| 久久久亚洲精品蜜桃臀| 成人资源影音先锋久久资源网| 香港aa三级久久三级老师2021国产三级精品三级在 | 国产成人99久久亚洲综合精品| 欧美激情一区二区久久久| 91久久精品视频| 国产亚洲欧美精品久久久| 无码乱码观看精品久久| 久久精品国产91久久麻豆自制| 伊人久久大香线蕉av不变影院 | 亚洲国产精品久久久久网站 | 久久99国产精品久久久| 国产精品一区二区久久精品涩爱| 久久精品免费一区二区三区| 久久精品亚洲精品国产色婷| 久久久久久综合网天天| 久久这里都是精品| 伊人久久亚洲综合影院| 伊人久久五月天| 久久久久久久免费视频| 中文字幕无码av激情不卡久久| 久久久久18| 日本亚洲色大成网站WWW久久| 久久久久国产日韩精品网站| 日本久久中文字幕|