SQLite C Interface - Opening A New Database Connection

intsqlite3_open(
constchar*filename,/*Databasefilename(UTF-8)*/

sqlite3
**ppDb/*OUT:SQLitedbhandle*/

);
int
sqlite3_open16(
constvoid*filename,/*Databasefilename(UTF-16)*/

sqlite3
**ppDb/*OUT:SQLitedbhandle*/

);
int
sqlite3_open_v2(
constchar*filename,/*Databasefilename(UTF-8)*/

sqlite3
**ppDb,/*OUT:SQLitedbhandle*/

intflags,/*Flags*/

constchar*zVfs/*NameofVFSmoduletouse*/

);

These routines open an SQLite database file whose name is given by the filename argument. The filename argument is interpreted as UTF-8 for sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte order for sqlite3_open16(). A database connection handle is usually returned in *ppDb,even if an error occurs. The only exception is that if SQLite is unable to allocate memory to hold the sqlite3 object,a NULL will be written into *ppDb instead of a pointer to the sqlite3 object. If the database is opened (and/or created) successfully,then SQLITE_OK is returned. Otherwise an error code is returned. The sqlite3_errmsg() or sqlite3_errmsg16() routines can be used to obtain an English language description of the error.

这些例程打开filename参数提供的SQLite数据库文件。对于sqlite3_open()和sqlite3_open_v2(),filename参数按UTF-8解释;对于sqlite3_open16(),按本机字节序的UTF-16解释。数据库连接句柄在*ppDb中返回,即使有错误发生。唯一的例外是,如果SQLite无法给sqlite3对象分配内存时,*ppDb将被写入NULL而不是sqlite3对象的指针。如果数据库被成功打开(和/或创建),则返回SQLITE_OK。否则返回错误码。sqlite3_errmsg()或sqlite3_errmsg16()例程可以用于获取错误的英文描述。

The default encoding for the database will be UTF-8 if sqlite3_open() or sqlite3_open_v2() is called and UTF-16 in the native byte order if sqlite3_open16() is used.

如果调用sqlite3_open()或sqlite3_open_v2(),数据库的默认编码将是UTF-8;如果使用sqlite3_open16(),则是本机字节序的UTF-16。

Whether or not an error occurs when it is opened,resources associated with the database connection handle should be released by passing it to sqlite3_close() when it is no longer required.

不管打开数据库的时候有没有错误发生,当不再需要它的时候,都应该将数据库连接句柄传递给sqlite3_close()来释放和它相关的资源。

The sqlite3_open_v2() interface works like sqlite3_open() except that it accepts two additional parameters for additional control over the new database connection. The flags parameter can take one of the following three values,optionally combined with the SQLITE_OPEN_NOMUTEX or SQLITE_OPEN_FULLMUTEX flags:

  • SQLITE_OPEN_READONLY
    The database is opened in read-only mode. If the database does not already exist,an error is returned.
  • SQLITE_OPEN_READWRITE
    The database is opened for reading and writing if possible,or reading only if the file is write protected by the operating system. In either case the database must already exist,otherwise an error is returned.
  • SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
    The database is opened for reading and writing,and is creates it if it does not already exist. This is the behavior that is always used for sqlite3_open() and sqlite3_open16().

sqlite3_open_v2()接口和sqlite3_open()的工作方式类似,但它接受两个额外的参数控制新的数据库连接。flags参数可以是下列三个值之一,并且可以选择性的组合SQLITE_OPEN_NOMUTEX或SQLITE_OPEN_FULLMUTEX标记:

  • SQLITE_OPEN_READONLY
    数据库以只读方式打开。如果数据库还不存在,返回错误。
  • SQLITE_OPEN_READWRITE
    如果可能的话,数据库以读写方式打开,或者如果该文件被操作系统保护,则以只读方式打开。在这两种情况下数据库都必须已经存在,否则返回错误。
  • SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
    数据库以读写方式打开,如果还不存在则创建它。这是sqlite3_open()和sqlite3_open16()总是使用的行为。

If the 3rd parameter to sqlite3_open_v2() is not one of the combinations shown above or one of the combinations shown above combined with the SQLITE_OPEN_NOMUTEX or SQLITE_OPEN_FULLMUTEX flags,then the behavior is undefined.

如果sqlite3_open_v2()的第3个参数不是上面所示的组合之一或上面所示的组合与SQLITE_OPEN_NOMUTEX或SQLITE_OPEN_FULLMUTEX的组合,则行为未定义。

If the SQLITE_OPEN_NOMUTEX flag is set,then the database connection opens in the multi-thread threading mode as long as the single-thread mode has not been set at compile-time or start-time. If the SQLITE_OPEN_FULLMUTEX flag is set then the database connection opens in the serialized threading mode unless single-thread was previously selected at compile-time or start-time.

如果设置了SQLITE_OPEN_NOMUTEX,只要没有在编译期或开始时设置单线程模式,数据库连接就以多线程线程模式打开。如果设置了SQLITE_OPEN_FULLMUTEX ,那么数据库连接以串行线程模式打开,除非之前在编译期或开始时选择了单线程。

If the filename is ":memory:",then a private,temporary in-memory database is created for the connection. This in-memory database will vanish when the database connection is closed. Future versions of SQLite might make use of additional special filenames that begin with the ":" character. It is recommended that when a database filename actually does begin with a ":" character you should prefix the filename with a pathname such as "./" to avoid ambiguity.

如果文件名是“:memory:”,那么为这个连接创建私有的、内存数据库。当数据库连接关闭时,这个内存数据库将不复存在。未来版本的SQLite可能使用以“:”开始的其他特殊文件名。当数据库文件名确实以“:”字符开始时,建议在文件名钱添加路径名前缀(例如“./”)来避免歧义。

If the filename is an empty string,temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed.

如果文件名是空字符串,那么将创建私有的、临时磁盘数据库。只要数据库连接被关闭,这个私有数据库就会被自动删除。

The fourth parameter to sqlite3_open_v2() is the name of the sqlite3_vfs object that defines the operating system interface that the new database connection should use. If the fourth parameter is a NULL pointer then the default sqlite3_vfs object is used.

sqlite3_open_v2() 的第4个参数是sqlite3_vfs对象的名字,它定义了新数据连接应当使用的操作系统接口。如果第4个参数是NULL指针,则使用默认的sqlite3_vfs对象。

Note to Windows users: The encoding used for the filename argument of sqlite3_open() and sqlite3_open_v2() must be UTF-8,not whatever codepage is currently defined. Filenames containing international characters must be converted to UTF-8 prior to passing them into sqlite3_open() or sqlite3_open_v2().

Windows用户注意:sqlite3_open()和sqlite_open_v2()的文件名参数编码必须是UTF-8。包含国际字符的文件名必须在传递给sqlite_open()或sqlite_open_v2()之前被转换为UTF-8。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


SQLite架构简单,又有Json计算能力,有时会承担Json文件/RESTful的计算功能,但SQLite不能直接解析Json文件/RESTful,需要用Java代码硬写,或借助第三方类库,最后再拼成insert语句插入数据表,代码非常繁琐,这里就不展示了。参考前面的代码可知,入库的过程比较麻烦,不能只用SQL,还要借助Java或命令行。SPL是现代的数据计算语言,属于简化的面向对象的语言风格,有对象的概念,可以用点号访问属性并进行多步骤计算,但没有继承重载这些内容,不算彻底的面向对象语言。...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite 是在世界上最广泛部署的 SQL 数据库引擎。SQLite 源代码不受版权限制。本教程将告诉您如何使用 SQLite 编程,并让你迅速上手。.................................
安卓开发,利用SQLite实现登陆注册功能
相比大多数数据库而言,具有等优势,广泛应用于、等领域。
有时候,一个项目只有一个数据库,比如只有SQLite,或者MySQL数据库,那么我们只需要使用一个固定的数据库即可。但是一个项目如果写好了,有多个用户使用,但是多个用户使用不同的数据库,这个时候,我们就需要把软件设计成可以连接多个数据库的模式,用什么数据库,就配置什么数据库即可。4.Users实体类,这个实体类要和数据库一样的,形成一一对应的关系。11.Sqlite数据库,需要在代码里面创建数据库,建立表,再建立数据。8.我们开启MySQL数据库,然后进行调试,看程序的结果。2.安装SqlSugar。
基于Android的背单词软件,功能强大完整。
SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统。说白了就是使用起来轻便简单,
Android的简单购物车案例
SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中。它是D.RichardHipp建立的公有领域项目。它的设计目标是嵌入式的,而且已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源的世界著名数据库...
Qt设计较为美观好看的登录注册界面(包含SQLite数据库以及TCP通信的应用)
SQLite是用C语言开发的跨平台小型数据库,可嵌入其他开发语言,也可在单机执行。SPL是用Java开发的跨平台的数据计算语言,可嵌入Java,可在单机执行,可以数据计算服务的形式被远程调用。两者的代码都是解释执行的。...
新建库.openDATA_BASE;新建表createtableLIST_NAME(DATA);语法:NAME关键字...<用逗号分割>删除表droptableNAME;查看表.schema查看表信息新建数据insertintoLIST_NAMEvalues();语法:CLASS,PARAMETER...,CLASS是类别,PARAMETER是参数<用逗号分割新建的
importsqlite3classDemo01:def__init__(self):self.conn=sqlite3.connect("sql_demo_001.db")self.cursor1=self.conn.cursor()self.cursor1.execute("select*fromtable_001wherename=?andid=?",('ssss&#0
 在客户端配置文件<configuration>节点下,添加:<connectionStrings>      <add name="localdb" connectionString="Data Source=config/local.db;Version=3;UseUTF16Encoding=True;" providerName="System.Data.SQLite.SQLiteFactory"/&g
提到锁就不得不说到死锁的问题,而SQLite也可能出现死锁。下面举个例子:连接1:BEGIN(UNLOCKED)连接1:SELECT...(SHARED)连接1:INSERT...(RESERVED)连接2:BEGIN(UNLOCKED)连接2:SELECT...(SHARED)连接1:COMMIT(PENDING,尝试获取EXCLUSIVE锁,但还有SHARED锁未释放,返回SQLITE_BUSY)连接2:INSERT...
SQLite是一种嵌入式数据库,它的数据库就是一个文件。由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成。Python就内置了SQLite3,所以,在Python中使用SQLite,不需要安装任何东西,直接使用。在使用SQLite前,我们先要搞清楚几个概念:表
设计思想————首先要确定有几个页面、和每个页面的大致布局由于是入门,我也是学习了不是很长的时间,所以项目比较low。。。。第一个页面,也就是打开APP的首页面:今天这个博客,先实现添加功能!:首先对主界面进行布局:其中activity_main.xml的代码为<?xmlversion="1.0"encoding="