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

推荐订阅源

G
Google Developers Blog
V
Vulnerabilities – Threatpost
A
Arctic Wolf
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
H
Hacker News: Front Page
D
Docker
人人都是产品经理
人人都是产品经理
Attack and Defense Labs
Attack and Defense Labs
Forbes - Security
Forbes - Security
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
aimingoo的专栏
aimingoo的专栏
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Simon Willison's Weblog
Simon Willison's Weblog
腾讯CDC
WordPress大学
WordPress大学
T
Tenable Blog
P
Proofpoint News Feed
月光博客
月光博客
T
Tor Project blog
The Cloudflare Blog
罗磊的独立博客
S
Secure Thoughts
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
I
Intezer
小众软件
小众软件
N
News | PayPal Newsroom
V
Visual Studio Blog
L
LINUX DO - 最新话题
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Troy Hunt's Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
D
DataBreaches.Net
P
Privacy International News Feed
博客园 - 三生石上(FineUI控件)
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Affairs
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
阮一峰的网络日志
阮一峰的网络日志

博客园 - answer

SQL查询重复记录 如何使用两台 NETGEAR 无线路由器进行无线中继(WDS) [转]取当前日期是在一年中的第几周 [转]写在UserControl销毁之时 给List排序( list sort) [转]检查本地DNS服务器是否正常工作及解决方法 SQLITE入门至精通 [转]WM手机,关于如何让手机一直运行下去,而不进入待机 [转]string表达式运算 [转]HTC G11 ROOT获取权限教程 [转]WebForm 与 winform 路径获取 [转]win7 系统装SQLServer2000 成功。 Mobile Development: Disable Windows Mobile 6.5 Start and Close Button [转]Windows Mobile: Hide StartButton in WinMo 6.5.x Windows CE 电源管理(转贴) [转]分享8个超棒的免费高质量图标搜索引擎 [转]Win7系统下VS2005_2008不识别WinCE5 SDK [转]windows 7 下ASP.net 本地配置 ( IIS 7) [转]SelectObject() 装载字体 VC EVC
[转]SQLite存取二进制数据
answer · 2011-02-24 · via 博客园 - answer

/*
程序功能:   使用SQLite的C API操作SQLite数据库,存取二进制数据.
             用来测试的文件都小于65535字节,没有测试更大的文件!
参考文档:   http://www.cntxk.com/CataNews/56/info8106.html
编译环境:   codeblock 10.05(svn 6906)
*/
#include <stdio.h>
#include <memory.h>
#include <sqlite3.h>

int main(int argc,char *argv[])
{
    sqlite3*    pDB=NULL;
    char*       pErrMsg;

    if(SQLITE_OK==sqlite3_open("./mydb.db",&pDB))
    {
        sqlite3_exec(pDB,"create table bList(fileName varchar(16) primary key, binData blob);",NULL,NULL,&pErrMsg);
        {
            char            buffer[65535];
            int             iLen=0;
            sqlite3_stmt*   stmt;

            {//存储二进制数据
                unsigned char hex[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
                sqlite3_prepare(pDB,"insert into bList values ('hex',?);",-1,&stmt,NULL);
                sqlite3_bind_blob(stmt,1,hex,16,NULL);
                sqlite3_step(stmt);
            }

            stmt=NULL;
            {//存储exe文件
                memset(buffer,0,65535);
                {
                    FILE* fp=fopen(argv[0],"rb");
                    iLen=fread(buffer,1,65535,fp);
                    fclose(fp);
                }
                sqlite3_prepare(pDB,"insert into bList values ('me.exe',?);",-1,&stmt,NULL);
                sqlite3_bind_blob(stmt,1,buffer,iLen,NULL);
                sqlite3_step(stmt);
            }

            stmt=NULL;
            {//存储普通c文档
                memset(buffer,0,65535);
                {
                    FILE* fp=fopen("../main.c","rb");
                    iLen=fread(buffer,1,65535,fp);
                    fclose(fp);
                }
                sqlite3_prepare(pDB,"insert into bList values ('main.txt',?);",-1,&stmt,NULL);
                sqlite3_bind_blob(stmt,1,buffer,iLen,NULL);
                sqlite3_step(stmt);
            }
            stmt=NULL;
            {//从数据库中读取txt文件数据
                char *data=NULL;
                memset(buffer,0,65535);
                sqlite3_prepare(pDB, "select binData from bList where fileName='main.txt';", -1, &stmt, 0);
                sqlite3_step(stmt);
                data= (char *)sqlite3_column_blob(stmt,0);//得到纪录中的BLOB字段
                iLen= sqlite3_column_bytes(stmt, 0);//得到字段中数据的长度
                memmove(buffer,data,iLen);
                printf("%s\n",buffer);
            }
        }
        sqlite3_close(pDB);
    }

    {
        puts("Press any key to exit...");
        getchar();
    }
    return 0;
}

From:

http://hi.baidu.com/ejoywx/blog/item/4d7b418c8677cc00b31bbae9.html