sqlite移植for symbian
直接去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)
{
return SQLITE_IOERR_WRITE;
}
return SQLITE_OK;
}
int FileTruncate(sqlite3_file* f, sqlite3_int64 size)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileSync(sqlite3_file* f, int flags)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileFileSize(sqlite3_file* f, sqlite3_int64 *pSize)
{
SymbianFile* file = (SymbianFile*) f;
TInt size = 0;
TInt err = file->iFile.Size(size);
if (err != KErrNone)
{
return SQLITE_OK;
}
*pSize = size;
return SQLITE_OK;
}
int FileLock(sqlite3_file* f, int)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileUnlock(sqlite3_file* f, int)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileCheckReservedLock(sqlite3_file* f, int *pResOut)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileFileControl(sqlite3_file* f, int op, void *pArg)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileSectorSize(sqlite3_file* f)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileDeviceCharacteristics(sqlite3_file* f)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
/* Methods above are valid for version 1 */
int FileShmMap(sqlite3_file* f, int iPg, int pgsz, int, void volatile**)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
int FileShmLock(sqlite3_file* f, int offset, int n, int flags)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
void FileShmBarrier(sqlite3_file* f)
{
SymbianFile* file = (SymbianFile*) f;
}
int FileShmUnmap(sqlite3_file* f, int deleteFlag)
{
SymbianFile* file = (SymbianFile*) f;
return SQLITE_OK;
}
static const sqlite3_io_methods Methord =
{ 100, /* iVersion */
FileClose, /* xClose */
FileRead, /* xRead */
FileWrite, /* xWrite */
FileTruncate, /* xTruncate */
FileSync, /* xSync */
FileFileSize, /* xFileSize */
FileLock, /* xLock */
FileUnlock, /* xUnlock */
FileCheckReservedLock, /* xCheckReservedLock */
FileFileControl, /* xFileControl */
FileSectorSize, /* xSectorSize */
FileDeviceCharacteristics, /* xDeviceCharacteristics */
FileShmMap, /* xShmMap */
FileShmLock, /* xSh
补充:移动开发 , 其他 ,