惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Palo Alto Networks Blog
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
博客园_首页
博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
P
Privacy & Cybersecurity Law Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Secure Thoughts
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Help Net Security
The Cloudflare Blog
Recorded Future
Recorded Future
Attack and Defense Labs
Attack and Defense Labs
J
Java Code Geeks
O
OpenAI News
T
Tor Project blog
B
Blog RSS Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
About on SuperTechFans
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
Cyberwarzone
Cyberwarzone
云风的 BLOG
云风的 BLOG
Security Latest
Security Latest
S
Schneier on Security
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Vulnerabilities – Threatpost
D
DataBreaches.Net
宝玉的分享
宝玉的分享
T
Troy Hunt's Blog
V
V2EX
Cisco Talos Blog
Cisco Talos Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Latest news
Latest news
量子位
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - zeus2

Xfire的初次使用 SQl Server 2012正式版发布 单例模式的三种实现方法 Oracle常用Hint Oracle 设计海量数据库 读书笔记(三) Oracle 设计海量数据库 读书笔记(二) Oracle 设计海量数据库 读书笔记(一) 解决中文ID3标签乱码zz 系统架构性能提高方案! 使用开源工具架设开发平台 修改SQL Server数据库地址 System.DateTimeOffset Load的问题 关于__doPostBack之前截获调用 - zeus2 - 博客园 当应用程序发布到iis7/iis7.5出现需要使用经典模式时 - zeus2 - 博客园 [读书笔记]SQL技术内幕Identity XML序列化封装 根据实体类生成查询安全版 生活太艰难了。!!! 从底层角度看ASP.NET-A low-level Look at the ASP.NET Architecture(转载)
C++访问Sqlite数据库(存档) - zeus2 - 博客园
zeus2 · 2008-11-09 · via 博客园 - zeus2

#include "stdafx.h"

#include "sqlite3.h"

sqlite3 * pDB;

int createTable()

{

    char* errMsg;

    std::string dropTab = "drop table test_tab;";

    string strSQL= "create table test_tab (f1 int, f2 long);";

    int res= sqlite3_exec(pDB , dropTab.c_str() , 0 , 0 , &errMsg);

    if (res != SQLITE_OK)

    {

        std::cout << "执行SQL 出错." << errMsg << std::endl;

        return -1;

    }

    res = sqlite3_exec(pDB , strSQL.c_str() ,0 ,0, &errMsg);

    if (res != SQLITE_OK)

    {

        std::cout << "执行创建tableSQL 出错." << errMsg << std::endl;

        return -1;

    }

    else

    {

        std::cout << "创建tableSQL成功执行."<< std::endl;

    }

    return 0;

}

int insert1()

{

    char* errMsg;

    int res = sqlite3_exec(pDB,"begin transaction;",0,0, &errMsg);

    for (int i= 1; i < 10; ++i)

    {

        std::stringstream strsql;

        strsql << "insert into test_tab  values(";

        strsql  << i << ","<< (i+10) << ");";

        std::string str = strsql.str();

        res = sqlite3_exec(pDB,str.c_str(),0,0, &errMsg);

        if (res != SQLITE_OK)

        {

            std::cout << "执行SQL 出错." << errMsg << std::endl;

            return -1;

        }

    }

    res = sqlite3_exec(pDB,"commit transaction;",0,0, &errMsg);

    std::cout << "SQL成功执行."<< std::endl;

    return 0;

}

static int callback(void *NotUsed, int argc, char **argv, char **azColName)

{

    for(int i = 0 ; i < argc ; i++)

    {

        std::cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") << ", " ;

    }

    std::cout<< "\n";

    return 0;

}

int select1()

{

    char* errMsg;

    string strSQL= "select * from test_tab;";

    int res = sqlite3_exec(pDB, strSQL.c_str(), callback , 0 , &errMsg);

    if (res != SQLITE_OK)

    {

        std::cout << "执行SQL 出错." << errMsg << std::endl;

        return -1;

    }

    else

    {

        std::cout << "SQL成功执行."<< std::endl;

    }

    return 0;

}

int _tmain(int argc, _TCHAR* argv[])

{

    int res = sqlite3_open("D:\\sql.db", &pDB);

    if( res ){

        std::cout << "Can't open database: "<< sqlite3_errmsg(pDB);

        sqlite3_close(pDB);

        return -1;

    }

    res = createTable();

    if (res != 0)

    {

        return 0;

    }

    res = insert1();

    if (res != 0)

    {

        return 0;

    }

    select1();

    getchar();

    return 0;

}