ubuntu sqlite3下C++向sqlite3插入数据的问题

Linux&sqlite3基本命令
系统平台:
sqlite3一款主要用于嵌入式的轻量级数据库,本文旨在为熟悉sqlite3基本命令提供技术文档。
&&&&&备注:本文所有操作均在用户下进行。
ubuntu下安装直接在终端运行命令:
#apt-get&install&sqlite3
查看版本信息:
#sqlite3&-version
2&、常用命令
当前目录下建立或打开数据库文件,并进入命令终端,以前缀标识:
#sqlite3&test.db
查看数据库文件信息命令注意命令前带字符:
sqlite&.database
查看所有表的创建语句:
sqlite&.schema
查看指定表的创建语句:
sqlite&.schema&table_name
以语句的形式列出表内容:
sqlite&.dump&table_name
设置显示信息的分隔符:
sqlite&.separator&symble
Example:设置显示信息以‘:’分隔
sqlite&.separator&:
设置显示模式:
sqlite&.mode&mode_name
Example:默认为,设置为,其他模式可通过查看相关内容
sqlite&.mode&column
输出帮助信息:
sqlite&.help
设置每一列的显示宽度:
sqlite&.width&width_value
Example:设置宽度为
sqlite&.width&2
列出当前显示格式的配置:
sqlite&.show
退出终端命令:
sqlite&.quit
sqlite&.exit
sql的指令格式:所有指令都是以分号结尾,两个减号则表示注释。
sqlite&create&studen_table(Stu_no&interger&PRIMARY&KEY,&Name&text&NOT&NULL,&Id&interger&UNIQUE,&Age&interger&CHECK(Age&6),&School&text&DEFAULT&'xx小学
该语句创建一个记录学生信息的数据表。
3.1&sqlite3存储数据的类型
NULL:标识一个值
INTERGER:整数类型
REAL:浮点数
TEXT:字符串
BLOB:二进制数
3.2&sqlite3存储数据的约束条件
Sqlite常用约束条件如下:
PRIMARY&KEY&-&主键:
1)主键的值必须唯一,用于标识每一条记录,如学生的学号
2)主键同时也是一个索引,通过主键查找记录速度较快
3)主键如果是整数类型,该列的值可以自动增长
NOT&NULL&-&非空:
约束列记录不能为空,否则报错
UNIQUE&-&唯一:
除主键外,约束其他列的数据的值唯一
CHECK&-&条件检查:
约束该列的值必须符合条件才可存入
DEFAULT&-&默认值:
列数据中的值基本都是一样的,这样的字段列可设为默认值
3.3&sqlite3常用指令
1)建立数据表
create&table&table_name(field1&type1,&field2&type1,&...);
table_name是要创建数据表名称,是数据表内字段名称,则是字段类型。
例,建立一个简单的学生信息表,它包含学号与姓名等学生信息:
create&table&student_info(stu_no&interger&primary&key,&name&text);
2)添加数据记录
insert&into&table_name(field1,&field2,&...)&values(val1,&val2,&...);
valx为需要存入字段的值。
例,往学生信息表添加数据:
Insert&into&student_info(stu_no,&name)&values(0001,&alex);
3)修改数据记录
update&table_name&set&field1=val1,&field2=val2&where&
where是语句中用于条件判断的命令,为判断表达式
例,修改学生信息表学号为的数据记录:
update&student_info&set&stu_no=0001,&name=hence&where&stu_no=0001;
4)删除数据记录
delete&from&table_name&[where&expression];
不加判断条件则清空表所有数据记录。
例,删除学生信息表学号为的数据记录:
delete&from&student_info&where&stu_no=0001;
5)查询数据记录
select指令基本格式:
select&columns&from&table_name&[where&expression];
a查询输出所有数据记录
select&*&from&table_
b限制输出数据记录数量
select&*&from&table_name&limit&
c升序输出数据记录
select&*&from&table_name&order&by&field&
d降序输出数据记录
select&*&from&table_name&order&by&field&
select&*&from&table_name&where&
select&*&from&table_name&where&field&in&('val1',&'val2',&'val3');
select&*&from&table_name&where&field&between&val1&and&val2;
f查询记录数目
select&count&(*)&from&table_
g区分列数据
select&distinct&field&from&table_
有一些字段的值可能会重复出现,去掉重复项,将列中各字段值单个列出。
6)建立索引
当说数据表存在大量记录,索引有助于加快查找数据表速度。
create&index&index_name&on&table_name(field);
例,针对学生表字段,建立一个索引:
create&index&student_index&on&student_table(stu_no);
建立完成后,在对该字段查询时,会自动使用该索引。
7)删除数据表或索引
drop&table&table_
drop&index&index_
参考资料:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。[转]&&&sqlite3-入门日记4-实现C++类封装
一、前言:
& & 今天试了下如何用C++类实现接口封装,感觉蛮好
。用于封装的类主要有两个,SQLiteStatement类和SQLiteWrapper类,是一个老外写的。我看了下源码,主要是对C接口进行了封
装,好处自然不用说,可以重用。很佩服老外的技巧,在这里就引用下他们的代码供大家分享下他们的思想。
源代码链接:&http://www.adp-gmbh.ch/sqlite/wrapper.html
二、类源码:
1.头文件:SQLiteWrapper.h
27 #ifndef SQLITE_WRAPPER_H__
28 &#define SQLITE_WRAPPER_H__ 29
30 #include &string& 31 #include &vector& 32
33 #include "sqlite3.h" 34
35 &class SQLiteStatement{ 36 &private: 37 //
SQLiteStatement's ctor only to be
called by SQLiteWrapper 38 & friend class SQLiteW 39 SQLiteStatement(std::string const& statement, sqlite3* db); 40
41 &public: 42 SQLiteStatement(); 43
44 enum dataType{ 45 INT=SQLITE_INTEGER, 46 FLT=SQLITE_FLOAT, 47 TXT=SQLITE_TEXT, 48 BLB=SQLITE_BLOB, 49 NUL=SQLITE_NULL, 50 }; 51
52 dataType DataType(int pos_zero_indexed); 53
54 int ValueInt(int pos_zero_indexed); 55 std::string ValueString(int pos_zero_indexed); 56
57 &// SQLiteStatement(const
SQLiteStatement&); 58 & ~SQLiteStatement(); 59
60 //SQLiteStatement&
operator=(SQLiteStatement
const&); 61 & 62 bool Bind(int pos_zero_indexed, std::string const& value); 63 bool Bind(int pos_zero_indexed, double value); 64 bool Bind(int pos_zero_indexed, int value); 65 bool BindNull(int pos_zero_indexed); 66
67 bool Execute(); 68
69 bool NextRow(); 70
73 bool Reset(); 74
75 bool RestartSelect(); 76
77 &private: 78 //void
DecreaseRefCounter(); 79
ref_counter_; //
not yet used... 81 & sqlite3_stmt* stmt_; 82 }; 83
84 &class SQLiteWrapper { 85 &public: 86 SQLiteWrapper(); 87
88 bool Open(std::string const& db_file); 89
90 class ResultRecord { 91 public: 92 std::vector&std::string& fields_; 93 }; 94
95 class ResultTable { 96 friend class SQLiteW 97 public: 98 ResultTable():ptr_cur_record_(0){} 99
100 std::vector&ResultRecord& records_;101
102 ResultRecord* next(){103 if (ptr_cur_record_&records_.size()){104 return &(records_[ptr_cur_record_++]);105 }106 return 0;107 }108
109 private:110 void reset(){111 records_.clear();112 ptr_cur_record_=0;113 }114
115 private:116 unsigned int ptr_cur_record_;117 };118
119 bool SelectStmt(std::string const& stmt,ResultTable& res);120 bool DirectStatement(std::string const& stmt);121 SQLiteStatement* Statement(std::string const& stmt);122
123 std::string LastError();124
125 // Transaction related126 & bool Begin();127 bool Commit();128 bool Rollback();129
130 private:131
132 static int SelectCallback(void *p_data,int num_fields,char **p_fields,char **p_col_names);133
134 sqlite3* db_;135 };136
137 #endif
2.类实现文件:SQLiteWrapper.cpp
28 #include "SQLiteWrapper.h" 29 //
TODO: raus 30 #include &windows.h& 31
32 SQLiteWrapper::SQLiteWrapper():db_(0){
35 bool SQLiteWrapper::Open(std::string const& db_file){ 36 if(sqlite3_open(db_file.c_str(),&db_)!=SQLITE_OK){ 37 return false; 38 } 39 return true; 40 } 41
42 bool SQLiteWrapper::SelectStmt(std::string
const& stmt,ResultTable& res){ 43 char * 44 int
46 res.reset(); 47
48 ret=sqlite3_exec(db_,stmt.c_str(),SelectCallback,static_cast&void*&(&res),&errmsg);
(ret!=SQLITE_OK){ 51 return false; 52 } 53 return true; 54 //
if (ret != SQLITE_OK) {
55 // std::cout
56 // } 57 } 58
59 // TODO
parameter p_col_names 60 int SQLiteWrapper::SelectCallback(void *p_data,int num_fields,char **p_fields,char** p_col_names) { 61 ResultTable* res=reinterpret_cast&ResultTable*&(p_data); 62
63 ResultR 64
SQLITE_WRAPPER_REPORT_COLUMN_NAMES 66 //
Hubert Castelain: column names in the
first row of res if res is empty 67
68 if(res-&records_.size()==0)
{ 69 ResultRecord col_ 70
71 for(int
i=0;i&num_i++){ 72 if(p_fields[i]) 73 col_names.fields_.push_back(p_col_names[i]);
74 else 75 col_names.fields_.push_back("(null)");
// or what else ? 76 } 77 res-&records_.push_back(col_names);
78 } 79 #endif 80
81 for(int
i=0;i&num_i++)
{ 82 // Hubert
Castelain: special treatment if null 83 if(p_fields[i]) 84 record.fields_.push_back(p_fields[i]);
86 record.fields_.push_back("&null&");
89 res-&records_.push_back(record);
91 return 0; 92 } 93
94 SQLiteStatement* SQLiteWrapper::Statement(std::string const& statement){ 95 SQLiteStatement*
96 try{ 97 stmt=new
SQLiteStatement(statement,db_);
99 }100 catch(const char*
e){101 return 0;102 }103 }104
105 SQLiteStatement::SQLiteStatement(std::string
const& statement,sqlite3* db)
{106 if(sqlite3_prepare(107 db, 108 statement.c_str(), // stmt109 -1,
110 &stmt_,111 0
112 )113 !=SQLITE_OK){114 throw sqlite3_errmsg(db);115 }116
117 if(!stmt_){118 throw "stmt_ is
0";119 }120 }121
122 SQLiteStatement::~SQLiteStatement(){123
125 // 语法: int
sqlite3_finalize(sqlite3_stmt *pStmt);126 if(stmt_)
sqlite3_finalize(stmt_);127 }128
129 SQLiteStatement::SQLiteStatement():130
stmt_(0)131 {132 }133
134 bool SQLiteStatement::Bind(int pos_zero_indexed,std::string const& value){135 if (sqlite3_bind_text(136 stmt_,137 pos_zero_indexed+1,
// 通配符索引138 value.c_str(),139 value.length(), // 文本长度140 SQLITE_TRANSIENT // SQLITE_TRANSIENT: SQLite 自我复制141 )142 !=SQLITE_OK)
{143 return false;144 }145 return true;146 }147
148 bool SQLiteStatement::Bind(int pos_zero_indexed, double value) {149 if(sqlite3_bind_double(150 stmt_,151 pos_zero_indexed+1,
// 通配符索引152 value153 )154 !=SQLITE_OK)
{155 return false;156 }157 return true;158 }159
160 bool SQLiteStatement::Bind(int pos_zero_indexed,int value)
{161 if (sqlite3_bind_int(162 stmt_,163 pos_zero_indexed+1,
// 通配符索引164 value 165 )166 !=SQLITE_OK){167 return false;168 }169 return true;170 }171
172 bool SQLiteStatement::BindNull(int pos_zero_indexed){173 if (sqlite3_bind_null(174 stmt_,175 pos_zero_indexed+1
// 通配符索引176 )177 !=SQLITE_OK)
{178 return false;179 }180 return true;181 }182
183 bool SQLiteStatement::Execute()
{184 int rc=sqlite3_step(stmt_);185 if (rc==SQLITE_BUSY){186 ::MessageBox(0,"SQLITE_BUSY",0,0); 187 return false;188 }189 if(rc==SQLITE_ERROR){190 ::MessageBox(0,"SQLITE_ERROR",0,0); 191 return false;192 }193 if(rc==SQLITE_MISUSE){194 ::MessageBox(0,"SQLITE_ERROR",0,0); 195 return false;196 }197 if(rc!=SQLITE_DONE){198 //sqlite3_reset(stmt_);199 return false;200 }201 sqlite3_reset(stmt_);202 return true;203 }204
205 SQLiteStatement::dataType
SQLiteStatement::DataType(int pos_zero_indexed){206 return dataType(sqlite3_column_type(stmt_,
pos_zero_indexed));207 }208
209 int SQLiteStatement::ValueInt(int pos_zero_indexed){210 return sqlite3_column_int(stmt_,pos_zero_indexed);211
213 std::string SQLiteStatement::ValueString(int pos_zero_indexed){214 return std::string(reinterpret_cast&const char*&(sqlite3_column_text(stmt_,pos_zero_indexed)));
217 bool SQLiteStatement::RestartSelect(){218
sqlite3_reset(stmt_);219 return true;220 }221
222 bool SQLiteStatement::Reset(){223
int rc=sqlite3_step(stmt_);224
225 sqlite3_reset(stmt_);226
227 if (rc==SQLITE_ROW) return true;228 return false;229 }230
231 bool SQLiteStatement::NextRow()
{232 int rc=sqlite3_step(stmt_);233
234 if (rc==SQLITE_ROW){235 return true;236 }237 if(rc==SQLITE_DONE){238 sqlite3_reset(stmt_);239 return false;240 } 241 else if(rc==SQLITE_MISUSE){242 ::MessageBox(0,"SQLiteStatement::NextRow
SQLITE_MISUSE",0,0);243 } 244 else if(rc==SQLITE_BUSY){245 ::MessageBox(0,"SQLiteStatement::NextRow
SQLITE_BUSY",0,0);
246 } 247 else if(rc==SQLITE_ERROR){248 ::MessageBox(0,"SQLiteStatement::NextRow
SQLITE_ERROR",0,0);249 }250 return false;251 }252
253 bool SQLiteWrapper::DirectStatement(std::string
const& stmt){254 char *255 int 256
257 ret=sqlite3_exec(db_,stmt.c_str(),0,0,&errmsg);258
259 if(ret!=SQLITE_OK)
{260 return false;261 }262 return true;263
264 //if(ret !=
SQLITE_OK) {265
// std::cout && stmt
//}267 }268
269 std::string SQLiteWrapper::LastError(){270
return sqlite3_errmsg(db_);271 }272
273 bool SQLiteWrapper::Begin(){274 return DirectStatement("begin");275 }276
277 bool SQLiteWrapper::Commit(){278 return DirectStatement("commit");279 }280
281 bool SQLiteWrapper::Rollback(){282
return DirectStatement("rollback");283 }
3.实例文件:
3.1 创建数据库和数据库表:Create_DB_Table.cpp
7 #include &iostream& 8 #include "SQLiteWrapper.h" 9
10 int main()
{11 SQLiteW12 if
(sqlite.Open("SQLiteWrapper.db"))
{13 std::cout&&"SQLiteWrapper.db
created or opened"&&std::
14 }15 else {16 std::cout&&"couldn't
open SQLiteWrapper.db"&&std::
19 if(sqlite.DirectStatement("Create
table foo(bar,baz)")){20 std::cout&&"table
foo created"&&std::
21 }22 else23 std::cout&&"couldn't
insert into foo"&&std::
24 25 return 0;26 }
3.2 插入数据:Insert_DB_Data.cpp
5 #include &iostream& 6
7 #include "SQLiteWrapper.h" 8
9 int main()
{10 SQLiteW11 if
(sqlite.Open("SQLiteWrapper.db"))
{12 std::cout&&"SQLiteWrapper.db
created or opened"&&std::
13 }14 else {15 std::cout&&"couldn't
open SQLiteWrapper.db"&&std::
18 if(sqlite.DirectStatement("insert into
foo values(1,2)")){19 std::cout&&"values(1,2)
into foo inserted"&&std::
20 21 }22 else23 std::cout&&"couldn't
insert into foo"&&std::
24 25 return 0;26 }
3.3 绑定参数执行:Bind_Param_Execute.cpp
5 #include &iostream& 6
7 #include "SQLiteWrapper.h" 8
9 int main(){10 SQLiteW11 if(sqlite.Open("SQLiteWrapper.db")){12 std::cout&&"SQLiteWrapper.db
created or opened"&&std::
13 }14 else{15 std::cout&&"couldn't
open SQLiteWrapper.db"&&std::
18 SQLiteStatement* stmt=sqlite.Statement("insert into
foo values(?,?)");19
20 if(stmt-&Bind(0,3)){21 std::cout&&"value
3 successfully bound at pos 0"&&std::
22 }23 else{24 std::cout&&"value
3 NOT successfully bound at pos 0: "&&sqlite.LastError()&&std::
25 }26 if(stmt-&Bind(1,
4)){27 std::cout&&"value
4 successfully bound at pos 1"&&std::
28 }29 else{30 std::cout&&"value
4 NOT successfully bound at pos 1:"&&sqlite.LastError()&&std::
33 // 第一次执行Execute34 if(stmt-&Execute()){35 std::cout&&"statement
executed"&&std::
36 }37 else{38 std::cout&&"error
executing statement: "&&sqlite.LastError()&&std::
41 if(stmt-&Bind(0,
5)){42 std::cout&&"value
5 successfully bound at pos 0"&&std::
43 }44 else{45 std::cout&&"value
5 NOT successfully bound at pos 0"&&std::
48 if(stmt-&Bind(1,
6)){49 std::cout&&"value
6 successfully bound at pos 1"&&std::
50 }51 else{52 std::cout&&"value
6 NOT successfully bound at pos 1"&&std::
55 // 第二次执行Execute56 if(stmt-&Execute()){57 std::cout&&"statement
executed"&&std::
58 }59 else {60 std::cout&&"error
executing statement: "&&sqlite.LastError()&&std::
63 return 0;64 }
3.4 输出数据库数据:Print_DB_Data.cpp
8 #include &iostream& 9 #include "SQLiteWrapper.h"10
11 int main(){12 SQLiteW13 if
(sqlite.Open("SQLiteWrapper.db")){14 std::cout&&"SQLiteWrapper.db
created or opened"&&std::
15 }16 else{17 std::cout&&"couldn't
open SQLiteWrapper.db"&&std::
20 SQLiteStatement* stmt=sqlite.Statement("select *
from foo");21
22 while(stmt-&NextRow()){23 std::cout&&stmt-&DataType
- "&&stmt-&DataType
24 stmt-&ValueString(0)&&"
- "&&stmt-&ValueString(1)&&std::
27 return 0;28 }
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。Ubuntu下wxWidgets学生公寓管理编程,sqlite3的用法(mysql数据库),窗体,下面是部分添加和删除... - 推酷
Ubuntu下wxWidgets学生公寓管理编程,sqlite3的用法(mysql数据库),窗体,下面是部分添加和删除...
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
以下是学生公寓信息管理的增加和删除,仅供参考。。
void StuManaFrame::OnAdd(wxCommandEvent &event)
& &//add student's dormitory infomation
& & sqlite3 *db=NULL;
& & char *
flag = sqlite3_open(&./stuinfo.db&,&db);
if(SQLITE_OK != flag)
& & & & wxLogMessage(&Database connect failed!&);
& & char id[20], name[20], dorid[20], phone[20], qq[20];
& & strcpy(id, m_id-&GetValue().mb_str());
& & strcpy(name, m_name-&GetValue().mb_str());
& & strcpy(dorid, m_dormitoryid-&GetValue().mb_str());
& & strcpy(phone, m_phone-&GetValue().mb_str());
& & strcpy(qq, m_qq-&GetValue().mb_str());
& & if(strcmp(&&, id) == 0)
& & & &wxLogMessage(&the stu's id can not be null&);
& & &if(strcmp(&&, name) == 0)
& & & &wxLogMessage(&the stu's name can not be null&);
& & char st[500];
& & sprintf(st, &insert into stu values('%s', '%s', '%s', '%s', '%s');&,
& & & & & & id, name, dorid, phone, qq);
& & sqlite3_exec(db,st,NULL,NULL,&errmsg );
& & wxLogMessage(wxString(errmsg));
& & sqlite3_close(db);
void StuManaFrame::OnDelete(wxCommandEvent &event)
& &//delete student's dormitory infomation
& & sqlite3 *db=NULL;
& & char *
& & char stuid[20];
flag = sqlite3_open(&./stuinfo.db&,&db);
if(SQLITE_OK != flag)
& & & & wxLogMessage(&Database connect failed!&);
& & strcpy(stuid, m_deleteid-&GetValue().mb_str());
& & if(strcmp(&&, stuid) == 1)
& & & &wxLogMessage(&the stu's id deleted can not be null&);
& & char *sql=sqlite3_mprintf(&delete from stu where id ='%s';&,stuid);
& & if(sqlite3_exec(db,sql,NULL,NULL,&errmsg) != SQLITE_OK)
& & & & wxLogMessage(&Error&);
& & & & wxLogMessage(errmsg);
& & & & wxLogMessage(&delete success!!&);
sqlite3建立数据库
1.先在线安装sqlite3,试用一下命令安装
ubuntu@ubuntu-virtual-machine:~$ sudo apt-get install sqlite3
2.安装成功后测试会出现
ubuntu@ubuntu-virtual-machine:~$ sqlite3
SQLite version 3.7.9
Enter &.help& for instructions
Enter SQL statements terminated with a &;&
sqlite& .exit
3.查找sqlite3的路径
ubuntu@ubuntu-virtual-machine:~$ which sqlite3
/usr/bin/sqlite3
ubuntu@ubuntu-virtual-machine:~$ ls
core & & & & & & &OSlab1 & &Public & & & & & & & & & & & & & Videos
Desktop & & & & & OSlab2 & &Qt & & & & & & & & & & & & & & & vmwaretools
Documents & & & & OSlab3 & &sqlite-amalgamation-3080403 & & &wx
Downloads & & & & OSlab4 & &sqlite-amalgamation-3080403.zip &wx3.0
examples.desktop &OSlab5 & &StuMana & & & & & & & & & & & & &wxlab
Music & & & & & & Pictures &Templates
4.具体sqlite3操作的实例
ubuntu@ubuntu-virtual-machine:~$ mkdir mydb
ubuntu@ubuntu-virtual-machine:~$ cd mydb
ubuntu@ubuntu-virtual-machine:~/mydb$ ls
ubuntu@ubuntu-virtual-machine:~/mydb$ sqlite3 stu.db
SQLite version 3.7.9
Enter &.help& for instructions
Enter SQL statements terminated with a &;&
sqlite& create table stu(sno int primary key, sname text not null, sage int);
sqlite& insert into stu(1, 'Lisi', 20);
Error: near &1&: syntax error
sqlite& insert into stu values(1, 'lisi', 20);
sqlite& insert into stu values(2, 'zhangsan', 18);
sqlite& select *
2|zhangsan|18
sqlite& .exit
ubuntu@ubuntu-virtual-machine:~/mydb$ ls
5.具体sqlite3操作的实例
ubuntu@ubuntu-virtual-machine:~$ cd StuMana
ubuntu@ubuntu-virtual-machine:~/StuMana$ sqlite3 stuinfo.db
SQLite version 3.7.9
Enter &.help& for instructions
Enter SQL statements terminated with a &;&
sqlite& create table stuinfo (id char(10),name char(15) not null,dormitoryid char(20) not null,phone char(11),qq char(13));
sqlite& insert into stuinfo values('','LiYa','15#501','','');
sqlite& insert into stuinfo values('','ZhangAihua','15#424','','');
sqlite& select *
|LiYa|15#501||
|ZhangAihua|15#424||
sqlite& .exit
ubuntu@ubuntu-virtual-machine:~/StuMana$ ls
bin & & & & & stuinfo.db & & &StuMana.depend & WxWizFrame.fbp
GUIFrame.cpp &StuManaApp.cpp &StuMana.layout & WxWizFrame.fbp.bak
GUIFrame.h & &StuManaApp.h & &StuManaMain.cpp
obj & & & & & StuMana.cbp & & StuManaMain.h
ubuntu@ubuntu-virtual-machine:~/StuMana$&
已发表评论数()
&&登&&&陆&&Ubuntu下安装sqlite3及常用SQL语句 - 好工具站长分享平台
Ubuntu下安装sqlite3及常用SQL语句
安装sqlite3命令如下:
1 sudo apt-get install sqlite3
创建或者打开已有的数据库文件:
1 sqlite3 test.db
进入数据库后,可以进行以下常用SQL语句操作:
CREATE TABLE ONT_USER_TABLE(
ONT_USER_NAME text PRIMARY KEY,
ONT_USER_PWD
text NOT NULL,
ONT_CREATE_TIME text
INSERT INTO ONT_USER_TABLE values('admin','123456',' 19:25');
UPDATE ONT_USER_TABLE SET ONT_USER_PWD = 'abcdefg';
DELETE FROM ONT_USER_TABLE WHERE ONT_USER_NAME = 'admin';
查询表结构代码如下:
查询当前已有的表
.Net 文章一周点击
.Net 文章一月点击
HaoGongJu.Net ( 好工具 ) All Rights Reserved温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
普通人一个
LOFTER精选
阅读(425)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
id:'fks_083',
blogTitle:'C/C++语言中调用 sqlite 的函数接口来实现对数据库的管理',
blogAbstract:'以下文章为网上收集,但全部经本人验证,全部可正确执行:如何在Linux下用C/C++语言操作数据库sqlite3作者:zieckey(.cn)All Rights Reserved!0. 引言我们这篇文章主要讲述了如何在C/C++语言中调用 sqlite 的函数接口来实现对数据库的管理,包括创建数据库、创建表格、插入数据、查询数据、删除数据等。1. 说明这里我们假设你已经编译好了sqlite的库文件 :libsqlite3.a libsqlite3.la libsqlite3.so libsqlite3.so.0 libsqlite3.so.0.8.6 pkgconfig和可执行文件 : sqlite3',
blogTag:'c/c++,sqlite3,api',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:6,
publishTime:3,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'普通人一个',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 sqlite3 导出表数据 的文章

 

随机推荐