Port sqlite for symbian

Source: Internet
Author: User

Go directly to the sqlite website to file a source code, and then change the file read/write interface to symbian. You can use it ..
 
 
 
But it should be noted that, do not make it into a dll, but do not support static in static lib. dll. If you want to make it into a dll, you need to put all the static in tls. I have tried, and there are many logics. And the changes are large. So static lib is enough ..
 
 
========================================================== ==========================================
 
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;
 
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,/* xShmLock */
 
FileShmBarrier,/* xShmBarrier */
 
FileShmUnmap/* xShmUnmap */
 
};
 
 
 
Int SymbianOpen (sqlite3_vfs * vfs, const char * zName, sqlite3_file * f,
 
Int flags, int * pOutFlags)
 
{
 
SymbianFile * file = (SymbianFile *) f;
 
 
 
Memset (file, 0, sizeof (SymbianFile ));
 
File-> pMethod = & Methord;
 
File-> pVfs = vfs;
 
 
 
Strcpy (file-> zPath, zName );
 
TInt err = file-> iFs. Connect ();
 
If (err! = KErrNone)
 
{
 
Return SQLITE_IOERR;
 
}
 
 
 
TFileName name;
 
Utf8ToUnicode (zName, name );
 
 
 
// RFile open
 
If (flags & SQLITE_OPEN_CREATE)
 
{
 
If (BaflUtils: FileExists (file-> iFs, name ))
 
{
 
Err = file-> iFile. Open (file-> iFs, name, EFileWrite | EFileRead );
 
}
 
Else
 
{
 
Err = file-> iFile. Replace (file-> iFs, name, EFileWrite | EFileRead );
 
 
 
}
 
}
 
Else
 
{
 
Err = file-> iFile. Open (file-> iFs, name, EFileWrite | EFileRead );
 
}
 
 
 
If (err! = KErrNone)
 
{
 
File-> iFs. Close ();
 
Return SQLITE_IOERR;
 
}
 
 
 
If (pOutFlags)
 
{
 
* POutFlags = flags;
 
}
 
 
 
Return SQLITE_ OK;
 
}
 
Int SymbianDelete (sqlite3_vfs *, const char * zName, int syncDir)
 
{
 
RFs fs;
 
TInt err = fs. Connect ();
 
If (err! = KErrNone)
 
{
 
Return SQLITE_IOERR;
 
}
 
TFileName name;
 
Utf8ToUnicode (zName, name );
 
Fs. Delete (name );
 
Fs. Close ();
 
Return SQLITE_ OK;
 
}
 
Int SymbianAccess (sqlite3_vfs *, const char * zName, int flags, int * pResOut)
 
{
 
* PResOut = flags;
 
Return SQLITE_ OK;
 
}
 
Int SymbianFullPathname (sqlite3_vfs * pVfs, const char * zRelative, int nFull,
 
Char * zFull)
 
{
 
Const char * temp = zRelative;
 
Temp = zFull;
 
 
 
Strcpy (zFull, zRelative );
 
 
 
Return SQLITE_ OK;
 
}
 
Void * SymbianDlOpen (sqlite3_vfs *, const char * zFilename)
 
{
 
Return NULL;
 
}
 
Void SymbianDlError (sqlite3_vfs *, int nByte, char * zErrMsg)
 
{
 
}
 
 
 
Void SymbianDlClose (sqlite3_vfs *, void *)
 
{
 
}
 
Int SymbianRandomness (sqlite3_vfs *, int nByte, char * zOut)
 
{
 
Return SQLITE_NOMEM;
 
}
 
Int SymbianSleep (sqlite3_vfs *, int microseconds)
 
{
 
Return SQLITE_NOMEM;
 
}
 
Int SymbianCurrentTime (sqlite3_vfs *, double *)
 
{
 
Return SQLITE_NOMEM;
 
}
 
Int SymbianGetLastError (sqlite3_vfs *, int, char *)
 
{
 
Return SQLITE_NOMEM;
 
}
 
/*
 
** The methods above are in version 1 of the sqlite_vfs object
 
** Definition. Those that follow are added in version 2 or later
 
*/
 
Int SymbianCurrentTimeInt64 (sqlite3_vfs *, sqlite3_int64 *)
 
{
 
Return 0;
 
}
 
 
 
SQLITE_API
 
Int sqlite3_ OS _init (void)
 
{
 
Static sqlite3_vfs symbianVfs =
 
{1,/* iVersion */
 
Sizeof (SymbianFile),/* szOsFile */
 
255,/* mxPathname */
 
0,/* pNext */
 
"Symbian",/* zName */
 
0,/* pAppData */
 
 
 
SymbianOpen,/* xOpen */
 
SymbianDelete,/* xDelete */
 
SymbianAccess,/* xAccess */
 
SymbianFullPathname,/* xFullPathname */
 
SymbianDlOpen,/* xDlOpen */
 
SymbianDlError,/* xDlError */
 
NULL/* SymbianDlSym */,/* xDlSym */
 
SymbianDlClose,/* xDlClose */
 
SymbianRandomness,/* xRandomness */
 
SymbianSleep,/* xSleep */
 
SymbianCurrentTime,/* xCurrentTime */
 
SymbianGetLastError,/* xGetLastError */
 
};
 
Sqlite3_vfs_register (& symbianVfs, 1 );
 
Return SQLITE_ OK;
 
}
 
 
 
SQLITE_API int sqlite3_ OS _end (void)
 
{
 
Return SQLITE_ OK;
 
}


From Hu zexin's blog

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.