• <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>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            SQLite Hello Code

            Posted on 2012-10-27 23:21 eryar 閱讀(1526) 評論(0)  編輯 收藏 引用
              1: //------------------------------------------------------------------------------
            
              2: //	Copyright (c) 2012 eryar All Rights Reserved.
            
              3: //
            
              4: //		File    : Main.cpp
            
              5: //		Author  : eryar@163.com
            
              6: //		Date    : 2012-10-27 23:01
            
              7: //		Version : 0.1v
            
              8: //
            
              9: //	Description : Test SQLite program.
            
             10: //
            
             11: //==============================================================================
            
             12: 
            
             13: #include <stdio.h>
            
             14: #include "sqlite3.h"
            
             15: 
            
             16: // Query callback function.
            
             17: int QueryCallback(void* data, int colCount, char** colValues, char** colName);
            
             18: 
            
             19: int main(int argc, char* argv[])
            
             20: {
            
             21:     int iResultCode = 0;
            
             22:     char*   szErrorMsg  = NULL;
            
             23:     const char* szCreateTableSQL = "create table users(name varchar(20) primary key, age int, birthday datetime);";
            
             24:     
            
             25:     // Connect to the database.
            
             26:     sqlite3*    pDB = NULL;
            
             27: 
            
             28:     iResultCode = sqlite3_open("test.db", &pDB);
            
             29: 
            
             30:     if (iResultCode != SQLITE_OK)
            
             31:     {
            
             32:         fprintf(stderr, "Cann't open database: %s\n", sqlite3_errmsg(pDB));
            
             33:         return 1;
            
             34:     }
            
             35: 
            
             36:     printf("Connected to the database successfully!\n");
            
             37: 
            
             38: 
            
             39:     // Execute the create table command.
            
             40:     iResultCode = sqlite3_exec(pDB, szCreateTableSQL, 0, 0, &szErrorMsg);
            
             41:     if (iResultCode != SQLITE_OK)
            
             42:     {
            
             43:         fprintf(stderr, "SQL error: %s! \n", szErrorMsg);
            
             44: 
            
             45:         sqlite3_free(szErrorMsg);
            
             46:     }
            
             47: 
            
             48:     // Insert records to the database.
            
             49:     iResultCode = sqlite3_exec(pDB, "insert into users values('張三', 20, '2012-10-27');", 0, 0, &szErrorMsg);
            
             50:     if (iResultCode)
            
             51:     {
            
             52:         printf("Insert a record to the database.\n");
            
             53:     }
            
             54: 
            
             55:     // Query the database.
            
             56:     iResultCode = sqlite3_exec(pDB, "select * from users;", QueryCallback, 0, &szErrorMsg);
            
             57: 
            
             58:     sqlite3_close(pDB);
            
             59: 
            
             60:     return 0;
            
             61: }
            
             62: 
            
             63: // For every record will call the callback function.
            
             64: // N records will call the callback function N times.
            
             65: int QueryCallback( void* data, int colCount, char** colValues, char** colName )
            
             66: {
            
             67:     for (int i = 0; i < colCount; i++)
            
             68:     {
            
             69:         printf("%s = %s\n", colName[i], colValues[i] == 0 ? "NULL":colValues[i]);
            
             70:     }
            
             71: 
            
             72:     return 0;
            
             73: }
            
             74: 

             

            輸出結果:

              1: Connected to the database successfully!
            
              2: name = 張三
            
              3: age = 20
            
              4: birthday = 2012-10-27
            
              5: Press any key to continue
            欧美激情精品久久久久久| 麻豆一区二区99久久久久| 97精品国产91久久久久久| 久久精品国产久精国产一老狼| 久久99国产精品成人欧美| 99久久精品国产综合一区| 欧美粉嫩小泬久久久久久久| 色综合久久综合网观看| 久久国产福利免费| 久久笫一福利免费导航| 久久精品国产亚洲AV不卡| 亚洲欧美日韩精品久久亚洲区| 三级片免费观看久久| 色综合久久无码中文字幕| MM131亚洲国产美女久久| 久久精品成人免费网站| 欧美精品一区二区久久| 久久精品国产久精国产一老狼| 男女久久久国产一区二区三区| 国产高潮国产高潮久久久91| 久久福利资源国产精品999| 亚洲精品乱码久久久久66| 国内精品人妻无码久久久影院| 国产激情久久久久影院小草| 久久午夜免费视频| yellow中文字幕久久网| 一本久久a久久精品亚洲| 久久国产精品偷99| 天堂久久天堂AV色综合| 久久久久国产精品三级网| 日产精品久久久久久久| 久久精品99久久香蕉国产色戒 | 久久婷婷是五月综合色狠狠| 国产免费久久精品99久久| 伊人热人久久中文字幕| 久久精品一区二区三区不卡| 国产韩国精品一区二区三区久久| 99久久99久久精品免费看蜜桃| 久久天天躁狠狠躁夜夜网站| 精品久久久噜噜噜久久久| 国产韩国精品一区二区三区久久|