sqlite移植for symbian
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 05:47 点击:次
直接去sqlite网站上档一个源码,然后把文件读写的接口改成symbian的。就可以用了。。
但是需要注意的是,别做成dll,只能做成static lib. dll里面不支持static,如果你非要做成dll,那需要把所有的static放到tls里面。我尝试过,逻辑比较多。而且改动较大。所以static lib就可以了。。
============================================================================
Name : sqlite_symbian.cpp
Author :
Version : 1.0
Copyright : Arthur Hu
Description : sqlite_symbian declaration
============================================================================
*/
#include "sqlite3.h"
#include "sqliteInt.h"
#include "os_common.h"
#include <f32file.h>
#include <stdio.h>
#include <string.h>
#include <bautils.h>
#include <utf.h>
void Utf8ToUnicode(const char* src, TDes& aDes)
{
const TUint8* ptr = (const TUint8*) src;
TPtrC8 srcPtr(ptr, User::StringLength(ptr));
CnvUtfConverter::ConvertToUnicodeFromUtf8(aDes, srcPtr);
}
typedef struct SymbianFile SymbianFile;
struct SymbianFile
{
const sqlite3_io_methods *pMethod; /*** Must be first ***/
sqlite3_vfs *pVfs; /* The VFS used to open this file */
RFs iFs;
RFile iFile;
unsigned char locktype; /* Type of lock currently held on this file */
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
char zPath[255]; /* Full pathname of this file */
};
int FileClose(sqlite3_file* f)
{
SymbianFile* file = (SymbianFile*) f;
file->iFile.Close();
file->iFs.Close();
return SQLITE_OK;
}
int FileRead(sqlite3_file* f, void* data, int len, sqlite3_int64 offset)
{
SymbianFile* file = (SymbianFile*) f;
TInt off = offset;
TInt err = file->iFile.Seek(ESeekStart, off);
if (err != KErrNone)
{
return SQLITE_IOERR_READ;
}
TPtr8 ptr((TUint8*) data, len);
err = file->iFile.Read(ptr);
if (err != KErrNone)
{
return SQLITE_IOERR_READ;
}
if (ptr.Length() < len)
{
return SQLITE_IOERR_SHORT_READ;
}
return SQLITE_OK;
}
int FileWrite(sqlite3_file* f, const void* data, int len, sqlite3_int64 offset)
{
SymbianFile* file = (SymbianFile*) f;
TInt off = offset;
TInt err = file->iFile.Seek(ESeekStart, off);
if (err != KErrNone)
{
return SQLITE_IOERR_WRITE;
}
TPtrC8 ptr((const TUint8*) data, len);
err = file->iFile.Write(ptr);
if (err != KErrNone)
但是需要注意的是,别做成dll,只能做成static lib. dll里面不支持static,如果你非要做成dll,那需要把所有的static放到tls里面。我尝试过,逻辑比较多。而且改动较大。所以static lib就可以了。。
============================================================================
Name : sqlite_symbian.cpp
Author :
Version : 1.0
Copyright : Arthur Hu
Description : sqlite_symbian declaration
============================================================================
*/
#include "sqlite3.h"
#include "sqliteInt.h"
#include "os_common.h"
#include <f32file.h>
#include <stdio.h>
#include <string.h>
#include <bautils.h>
#include <utf.h>
void Utf8ToUnicode(const char* src, TDes& aDes)
{
const TUint8* ptr = (const TUint8*) src;
TPtrC8 srcPtr(ptr, User::StringLength(ptr));
CnvUtfConverter::ConvertToUnicodeFromUtf8(aDes, srcPtr);
}
typedef struct SymbianFile SymbianFile;
struct SymbianFile
{
const sqlite3_io_methods *pMethod; /*** Must be first ***/
sqlite3_vfs *pVfs; /* The VFS used to open this file */
RFs iFs;
RFile iFile;
unsigned char locktype; /* Type of lock currently held on this file */
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
char zPath[255]; /* Full pathname of this file */
};
int FileClose(sqlite3_file* f)
{
SymbianFile* file = (SymbianFile*) f;
file->iFile.Close();
file->iFs.Close();
return SQLITE_OK;
}
int FileRead(sqlite3_file* f, void* data, int len, sqlite3_int64 offset)
{
SymbianFile* file = (SymbianFile*) f;
TInt off = offset;
TInt err = file->iFile.Seek(ESeekStart, off);
if (err != KErrNone)
{
return SQLITE_IOERR_READ;
}
TPtr8 ptr((TUint8*) data, len);
err = file->iFile.Read(ptr);
if (err != KErrNone)
{
return SQLITE_IOERR_READ;
}
if (ptr.Length() < len)
{
return SQLITE_IOERR_SHORT_READ;
}
return SQLITE_OK;
}
int FileWrite(sqlite3_file* f, const void* data, int len, sqlite3_int64 offset)
{
SymbianFile* file = (SymbianFile*) f;
TInt off = offset;
TInt err = file->iFile.Seek(ESeekStart, off);
if (err != KErrNone)
{
return SQLITE_IOERR_WRITE;
}
TPtrC8 ptr((const TUint8*) data, len);
err = file->iFile.Write(ptr);
if (err != KErrNone)
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>