• <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>
            流量統計:
            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    
            本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
            posted on 2011-08-02 14:12 日需博客 閱讀(1766) 評論(1)  編輯 收藏 引用 所屬分類: C C++技術文章轉載

            FeedBack:
            # re: Kompex SQLite Wrapper for C++ - Examples
            2012-09-21 18:09 | czp
            你把別網站上的代碼拷貝過來,有意思嗎?  回復  更多評論
              
            久久这里都是精品| 99久久99久久精品国产片果冻| 久久av无码专区亚洲av桃花岛| 日产精品久久久一区二区| 久久免费视频观看| 久久婷婷五月综合国产尤物app| 性高湖久久久久久久久| 亚洲国产精品久久| 少妇精品久久久一区二区三区| 国产亚洲精品美女久久久| 久久久久国产日韩精品网站| 亚洲AV伊人久久青青草原| 欧美牲交A欧牲交aⅴ久久| 久久伊人亚洲AV无码网站| 97r久久精品国产99国产精| 久久综合鬼色88久久精品综合自在自线噜噜 | 亚洲午夜无码久久久久| 嫩草影院久久国产精品| 精品久久人人爽天天玩人人妻| 久久97久久97精品免视看秋霞| 久久亚洲精精品中文字幕| 久久99热这里只频精品6| 国产一区二区三区久久精品| 久久国产劲爆AV内射—百度| 久久久精品国产Sm最大网站| 国产91色综合久久免费分享| 一本色道久久88精品综合| 久久久综合香蕉尹人综合网| 66精品综合久久久久久久| 丰满少妇人妻久久久久久| 色欲久久久天天天综合网精品| 色婷婷久久综合中文久久一本| 99久久无码一区人妻| 欧美综合天天夜夜久久| 99久久成人国产精品免费| 99久久777色| 久久国产乱子精品免费女| 久久久久久免费一区二区三区| 精品熟女少妇a∨免费久久| 久久99免费视频| 精品水蜜桃久久久久久久|