Sqlite3.78移植到VxWorks6.6

        移植sqlite3.78到VxWorks6.6是一个痛苦的过程,网上的资源也是少得可怜,功夫不负有心人,昨天自己通过windows与wxworks单步跟踪比较运行状况,折腾了几天的问题总算初步解决了,还有一些像线程互斥遗留问题日后解决吧。迷茫之时还特意向sqlite原作者请教,尽管从D. Richard Hipp那里没有得到帮助,这里我还是要感谢伟大的D. Richard Hipp:

A、第一封信

发件人:liuxuezong<liuxuezong@126.com>;

时 间:2011年09月28日 10:27 (星期三)

收件人:drh@hwaci.com

Dear D. Richard Hipp ,

       Hello, I recently transplanted sqlie3 to vxworks6.6, encountered some problems, please help me, thank you! Means there is no problem with memory, the following is vxworks6.6 debugging error message:

1, sqlite3.3.7, debugging error: database is locked;

2, sqlite3.7.8, debugging error: disk i / o error.

                                                                                                              liuxuezong                                                                                                                                            shanghai,china.                                                                                                               

2011.09.28

 

B、第二封信

发件人:liuxuezong<liuxuezong@126.com>;

时 间:2011年09月28日 16:05 (星期三)

收件人:drh@hwaci.com

Dear D. Richard Hipp ,

       hello, After debugging, I found the file control error s =- 1, leading to the above problem: database is locked!

...

lock.l_len = 1L;

lock.l_whence = SEEK_SET;

/* A PENDING lock is needed before acquiring a SHARED lock and before

  ** acquiring an EXCLUSIVE lock.  For the SHARED lock, the PENDING will

  ** be released.

*/

if( locktype==SHARED_LOCK

      || (locktype==EXCLUSIVE_LOCK && pFile->locktype<PENDING_LOCK)

  ){

    lock.l_type = (locktype==SHARED_LOCK?F_RDLCK:F_WRLCK);

    lock.l_start = PENDING_BYTE;

    s = fcntl(pFile->h, F_SETLK, &lock);

    if( s ){

      rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY;

      goto end_lock;

    }

  }

...

                                                                                                               liuxuezong                                                                                                                

shanghai,china.                                                                                                              

2011.09.28

 

C、Richard Hipp的回信

发件人:Richard Hipp<drh@sqlite.org>;(由 drhsqlite@gmail.com 代发)

时 间:2011年09月28日 17:57 (星期三)

收件人:liuxuezong <liuxuezong@126.com>;

Please send your requests to the SQLite mailing list.  sqlite-users@sqlite.org.  See http://www.sqlite.org/support.html for additional information.

 

 

2011/9/27 liuxuezong <liuxuezong@126.com>

 

- 显示引用文字 -

 

 

 

--

D. Richard Hipp

drh@sqlite.org

1、准备工作

    首先从网上下载一个Sqlite Developer 3.8.5管理工具,SharpPlus Sqlite Developer, 强大的Sqlite3数据库管理程序,具有如下功能:

☆、强大的SQL编辑器

☆、Sqlite Sql语法高亮

☆、Sql编辑历史

☆、Sql关键字自动完成

☆、括号高亮匹配

☆、表,字段名自动完成

☆、自动SQL语法错误提示

☆、支持Unicode

☆、SQL代码格式化器

☆、支持ANSI,UTF8和UTF16数据编辑.

☆、可定制的数据类型映射.

☆、可执行分号分割的多条SQL语句.

☆、SQL执行监视器.

☆、可视化查询设计器.

☆、可视化表 ,视图 ,触发器和索引编辑.

☆、可按文本,16进制,HTML或者位图形式编辑数据.

☆、支持查看和编辑临时表,视图和触发器.

☆、支持查询计划.

☆、自动更新.

☆、可以将数据导出为sql,csv,excel, word, html, xml.

☆、可以导入csv文件.

☆、可以导出数据库的元数据.

☆、支持数据库元数据查找

☆、可以中断长时间查询

☆、支持Sqlite可加载扩展及虚拟表

☆、多语言支持(英语,简体中文,日语)

其次从sqlite官方网上http://www.sqlite.org/download.html下载一个Sqlite3.85开源代码,怎么下载应该比较简单了!

打开Sqlite Developer程序,上面的Sample.db将是我们测试的数据源,我们将利用该数据库的部门表见下图“DEPARTMENT”进行验证是否正确,安装之后把Sample.db文件拷贝至$(FEPHOME)/db/目录下,在$(FEPHOME)/code/目录新建文件夹sqlite378,把下载的sqlite3.78包中的sqlite3.h和sqlite3ext.h拷贝此处。

 

2、测试代码

// testSQlite378.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite378/sqlite3.h" // $(FEPHOME)/code/inlcude/sqlite378

int main(int argc, char* argv[])
{
	sqlite3 *db = NULL;
	char *zErrMsg = 0;
	int rc;
	char *szWorkPath = "/e/openSUSE3000/fep/db/Sample.db3";
	rc = sqlite3_open(szWorkPath, &db); // 打开指定的数据库文件.
	if (rc)
	{
		fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
		sqlite3_close(db);
		return (1);
	}
	else 
	{
		printf("You have opened a sqlite3 database named Sample.db3 successfully!\n");
	
	}
	
	int nrow = 0, ncolumn = 0;
	char **azResult; // 二维数组存放结果
	
	// 查询数据
	char *sql = "SELECT * FROM DEPARTMENT";
	sqlite3_get_table(db, sql , &azResult , &nrow , &ncolumn , &zErrMsg);
	int i = 0 ;
	printf("row:%d column=%d \n" , nrow , ncolumn);
	printf("\nThe result of querying is : \n");
	for (i = 0 ; i < ( nrow + 1 ) * ncolumn ; i++)
		printf("azResult[%d] = %s\n", i , azResult[i]);
	
	// 释放掉  azResult 的内存空间
	sqlite3_free_table(azResult);
	
#ifdef _DEBUG_
	printf("zErrMsg = %s \n", zErrMsg);
#endif
	
	sqlite3_close(db); // 关闭数据库
	return 0;
}	

3、生成库代码libsqlite378

在生成库时需要一些配置,具体内容如下:

DEFINES:-DOS_VXWORKS=1 -D_HAVE_SQLITE_CONFIG_H -DSQLITE_THREADSAFE=0

OS_VXWORKS:说明使用操作系统VxWorks.

_HAVE_SQLITE_CONFIG_H:将使用配置文件“config.h”

#ifndef _CONFIG_H_
#define _CONFIG_H_

#define SQLITE_OMIT_LOAD_EXTENSION   1   // 不需要动态库支持
#define HAVE_UTIME                          // 使用utime函数而不是utimes函数
#include <semaphore.h>
/* 
* 不使用VxWorks提供的POSIX标准中的互斥信号量递归接口,因为对于内核程序,POSIX支持* 的不是太好
*/
#define SQLITE_HOMEGROWN_RECURSIVE_MUTEX    1   
#include <vxWorks.h>     
#endif // _CONFIG_H_

SQLITE_THREADSAFE=<0 or 1 or 2>

This option controls whether or not code is included in SQLite to enable it to operate safely in a multithreaded environment. The default is SQLITE_THREADSAFE=1 which is safe for use in a multithreaded environment. When compiled with SQLITE_THREADSAFE=0 all mutexing code is omitted and it is unsafe to use SQLite in a multithreaded program. When compiled with SQLITE_THREADSAFE=2, SQLite can be used in a multithreaded program so long as no two threads attempt to use the same database connection at the same time.

To put it another way, SQLITE_THREADSAFE=1 sets the default threading mode to Serialized. SQLITE_THREADSAFE=2 sets the default threading mode to Multi-threaded. And SQLITE_THREADSAFE=0 sets the threading mode to Single-threaded.

The value of SQLITE_THREADSAFE can be determined at run-time using the sqlite3_threadsafe() interface.

When SQLite has been compiled with SQLITE_THREADSAFE=1 or SQLITE_THREADSAFE=2 then the threading mode can be altered at run-time using the sqlite3_config() interface together with one of these verbs:

The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags to sqlite3_open_v2() can also be used to adjust the threading mode of individual database connections at run-time.

Note that when SQLite is compiled with SQLITE_THREADSAFE=0, the code to make SQLite threadsafe is omitted from the build. When this occurs, it is impossible to change the threading mode at start-time or run-time.

See the threading mode documentation for additional information on aspects of using SQLite in a multithreaded environment.

3、调试代码testsqlite378

    testsqlite378生成比较简单,具体可以看前面关于嵌入系统调试的内容了。


4、Console输出的内容:

You have opened a sqlite3 database named Sample.db3 successfully!

row:21 column=7

 

The result of querying is :

azResult[0] = DEPT_NO

azResult[1] = DEPARTMENT

azResult[2] = HEAD_DEPT

azResult[3] = MNGR_NO

azResult[4] = BUDGET

azResult[5] = LOCATION

azResult[6] = PHONE_NO

azResult[7] = 000

azResult[8] = Corporate Headquarters

azResult[9] =

azResult[10] = 105

azResult[11] = 1000000

azResult[12] = Monterey

azResult[13] = (408) 555-1234

azResult[14] = 100

azResult[15] = Sales and Marketing

azResult[16] = 000

azResult[17] = 85

azResult[18] = 2000000

azResult[19] = San Francisco

azResult[20] = (415) 555-1234

azResult[21] = 600

azResult[22] = Engineering

azResult[23] = 000

azResult[24] = 2

azResult[25] = 1100000

azResult[26] = Monterey

azResult[27] = (408) 555-1234

azResult[28] = 900

azResult[29] = Finance

azResult[30] = 000

azResult[31] = 46

azResult[32] = 400000

azResult[33] = Monterey

azResult[34] = (408) 555-1234

azResult[35] = 180

azResult[36] = Marketing

azResult[37] = 100

azResult[38] =

azResult[39] = 1500000

azResult[40] = San Francisco

azResult[41] = (415) 555-1234

azResult[42] = 620

azResult[43] = Software Products Div.

azResult[44] = 600

azResult[45] =

azResult[46] = 1200000

azResult[47] = Monterey

azResult[48] = (408) 555-1234

azResult[49] = 621

azResult[50] = Software Development

azResult[51] = 620

azResult[52] =

azResult[53] = 400000

azResult[54] = Monterey

azResult[55] = (408) 555-1234

azResult[56] = 622

azResult[57] = Quality Assurance

azResult[58] = 620

azResult[59] = 9

azResult[60] = 300000

azResult[61] = Monterey

azResult[62] = (408) 555-1234

azResult[63] = 623

azResult[64] = Customer Support

azResult[65] = 620

azResult[66] = 15

azResult[67] = 650000

azResult[68] = Monterey

azResult[69] = (408) 555-1234

azResult[70] = 670

azResult[71] = Consumer Electronics Div.

azResult[72] = 600

azResult[73] = 107

azResult[74] = 1150000

azResult[75] = Burlington VT

azResult[76] = (802) 555-1234

azResult[77] = 671

azResult[78] = Research and Development

azResult[79] = 670

azResult[80] = 20

azResult[81] = 460000

azResult[82] = Burlington VT

azResult[83] = (802) 555-1234

azResult[84] = 672

azResult[85] = Customer Services

azResult[86] = 670

azResult[87] = 94

azResult[88] = 850000

azResult[89] = Burlington VT

azResult[90] = (802) 555-1234

azResult[91] = 130

azResult[92] = Field Office: East Coast

azResult[93] = 100

azResult[94] = 11

azResult[95] = 500000

azResult[96] = Boston

azResult[97] = (617) 555-1234

azResult[98] = 140

azResult[99] = Field Office: Canada

azResult[100] = 100

azResult[101] = 72

azResult[102] = 500000

azResult[103] = Toronto

azResult[104] = (416) 677-1000

azResult[105] = 110

azResult[106] = Pacific Rim Headquarters

azResult[107] = 100

azResult[108] = 34

azResult[109] = 600000

azResult[110] = Kuaui

azResult[111] = (808) 555-1234

azResult[112] = 115

azResult[113] = Field Office: Japan

azResult[114] = 110

azResult[115] = 118

azResult[116] = 500000

azResult[117] = Tokyo

azResult[118] = 3 5350 0901

azResult[119] = 116

azResult[120] = Field Office: Singapore

azResult[121] = 110

azResult[122] =

azResult[123] = 300000

azResult[124] = Singapore

azResult[125] = 3 55 1234

azResult[126] = 120

azResult[127] = European Headquarters

azResult[128] = 100

azResult[129] = 36

azResult[130] = 700000

azResult[131] = London

azResult[132] = 71 235-4400

azResult[133] = 121

azResult[134] = Field Office: Switzerland

azResult[135] = 120

azResult[136] = 141

azResult[137] = 500000

azResult[138] = Zurich

azResult[139] = 1 211 7767

azResult[140] = 123

azResult[141] = Field Office: France

azResult[142] = 120

azResult[143] = 134

azResult[144] = 400000

azResult[145] = Cannes

azResult[146] = 58 68 11 12

azResult[147] = 125

azResult[148] = Field Office: Italy

azResult[149] = 120

azResult[150] = 121

azResult[151] = 400000

azResult[152] = Milan

azResult[153] = 2 430 39 39

从控制输出的内容,我们可以看出的结果与表格显示一致,那说明我们的移植成功了

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值