Some small cleanup and uniformisation arround the new createFunction() API

This commit is contained in:
Sébastien Rombauts 2014-02-06 22:48:35 +01:00
parent 5095b086e1
commit d6f5029f6c
4 changed files with 60 additions and 37 deletions

View File

@ -32,7 +32,7 @@ PROJECT_NAME = SQLiteC++
# This could be handy for archiving the generated documentation or # This could be handy for archiving the generated documentation or
# if some version control system is used. # if some version control system is used.
PROJECT_NUMBER = 0.5.0 PROJECT_NUMBER = 0.7.0
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer # for a project that appears at the top of each page and should give viewer

View File

@ -100,17 +100,24 @@ void Database::check(const int aRet) const // throw(SQLite::Exception)
} }
} }
// Attach a custom function to your sqlite database. // Attach a custom function to your sqlite database. Assumes UTF8 text representation.
// assumes UTF8 text representation.
// Parameter details can be found here: http://www.sqlite.org/c3ref/create_function.html // Parameter details can be found here: http://www.sqlite.org/c3ref/create_function.html
void Database::createFunction(const char *funcName, int nArg, bool deterministic, void *pApp, void (*xFunc)(sqlite3_context *, int, sqlite3_value **), void (*xStep)(sqlite3_context *, int, sqlite3_value **), void (*xFinal)(sqlite3_context *), void (*xDestroy)(void *)) void Database::createFunction(const char* apFuncName,
int aNbArg,
bool abDeterministic,
void* apApp,
void (*apFunc)(sqlite3_context *, int, sqlite3_value **),
void (*apStep)(sqlite3_context *, int, sqlite3_value **),
void (*apFinal)(sqlite3_context *),
void (*apDestroy)(void *))
{ {
int eTextRep = SQLITE_UTF8; int TextRep = SQLITE_UTF8;
// optimization if deterministic function... e.g. of non deterministic function (random()) // optimization if deterministic function (e.g. of nondeterministic function random())
if (deterministic) { if (abDeterministic) {
eTextRep = eTextRep|SQLITE_DETERMINISTIC; TextRep = TextRep|SQLITE_DETERMINISTIC;
} }
int ret = sqlite3_create_function_v2(mpSQLite, funcName, nArg, eTextRep, pApp, xFunc, xStep, xFinal, xDestroy); int ret = sqlite3_create_function_v2(mpSQLite, apFuncName, aNbArg, TextRep,
apApp, apFunc, apStep, apFinal, apDestroy);
check(ret); check(ret);
} }

View File

@ -231,47 +231,63 @@ public:
} }
/** /**
* @brief Create a function in the sqlite database. * @brief Create or redefine a SQL function or aggregate in the sqlite database.
* *
* This is the equivalent of the sqlite3_create_function_v2 command. * This is the equivalent of the sqlite3_create_function_v2 command.
* NOTE: UTF-8 text encoding assumed. * @see http://www.sqlite.org/c3ref/create_function.html
* *
* @note UTF-8 text encoding assumed.
* *
* @param[in] funcName Name of the SQL function to be created or redefined * @param[in] apFuncName Name of the SQL function to be created or redefined
* @param[in] nArg Number of arguments in the function * @param[in] aNbArg Number of arguments in the function
* @param[in] determininistic optimize for deterministic functions. Most sqlite functions are deterministic. * @param[in] abDeterministic Optimize for deterministic functions (most are). A random number generator is not.
* a random number generator is an example of an indeterministic function. * @param[in] apApp Arbitrary pointer ot user data, accessible with sqlite3_user_data().
* @param[in] pApp See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apFunc Pointer to a C-function to implement a scalar SQL function (apStep & apFinal NULL)
* @param[in] xFunc See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apStep Pointer to a C-function to implement an aggregate SQL function (apFunc NULL)
* @param[in] xStep See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apFinal Pointer to a C-function to implement an aggregate SQL function (apFunc NULL)
* @param[in] xFinal See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apDestroy If not NULL, then it is the destructor for the application data pointer.
* @param[in] xDestroy See: http://www.sqlite.org/c3ref/create_function.html
* *
* @throw SQLite::Exception in case of error * @throw SQLite::Exception in case of error
*/ */
void createFunction(const char *funcName, int nArg, bool deterministic, void *pApp, void (*xFunc)(sqlite3_context *, int, sqlite3_value **), void (*xStep)(sqlite3_context *, int, sqlite3_value **), void (*xFinal)(sqlite3_context *), void (*xDestroy)(void *)); void createFunction(const char* apFuncName,
int aNbArg,
bool abDeterministic,
void* apApp,
void (*apFunc)(sqlite3_context *, int, sqlite3_value **),
void (*apStep)(sqlite3_context *, int, sqlite3_value **),
void (*apFinal)(sqlite3_context *),
void (*axDestroy)(void *));
/** /**
* @brief Create a function in the sqlite database. * @brief Create or redefine a SQL function or aggregate in the sqlite database.
* *
* This is the equivalent of the sqlite3_create_function_v2 command. * This is the equivalent of the sqlite3_create_function_v2 command.
* NOTE: UTF-8 text encoding assumed. * @see http://www.sqlite.org/c3ref/create_function.html
* *
* @note UTF-8 text encoding assumed.
* *
* @param[in] funcName Name of the SQL function to be created or redefined * @param[in] aFuncName Name of the SQL function to be created or redefined
* @param[in] nArg Number of arguments in the function * @param[in] aNbArg Number of arguments in the function
* @param[in] determininistic optimize for deterministic functions. Most sqlite functions are deterministic. * @param[in] abDeterministic Optimize for deterministic functions (most are). A random number generator is not.
* a random number generator is an example of an indeterministic function. * @param[in] apApp Arbitrary pointer ot user data, accessible with sqlite3_user_data().
* @param[in] pApp See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apFunc Pointer to a C-function to implement a scalar SQL function (apStep & apFinal NULL)
* @param[in] xFunc See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apStep Pointer to a C-function to implement an aggregate SQL function (apFunc NULL)
* @param[in] xStep See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apFinal Pointer to a C-function to implement an aggregate SQL function (apFunc NULL)
* @param[in] xFinal See: http://www.sqlite.org/c3ref/create_function.html * @param[in] apDestroy If not NULL, then it is the destructor for the application data pointer.
* @param[in] xDestroy See: http://www.sqlite.org/c3ref/create_function.html
* *
* @throw SQLite::Exception in case of error * @throw SQLite::Exception in case of error
*/ */
inline void createFunction(const std::string &funcName, int nArg, bool deterministic, void *pApp, void (*xFunc)(sqlite3_context *, int, sqlite3_value **), void (*xStep)(sqlite3_context *, int, sqlite3_value **), void (*xFinal)(sqlite3_context *), void (*xDestroy)(void *)) inline void createFunction(const std::string& aFuncName,
int aNbArg,
bool abDeterministic,
void* apApp,
void (*apFunc)(sqlite3_context *, int, sqlite3_value **),
void (*apStep)(sqlite3_context *, int, sqlite3_value **),
void (*apFinal)(sqlite3_context *),
void (*apDestroy)(void *))
{ {
return createFunction(funcName.c_str(), nArg, deterministic, pApp, xFunc, xStep, xFinal, xDestroy); return createFunction(aFuncName.c_str(), aNbArg, abDeterministic,
apApp, apFunc, apStep, apFinal, apDestroy);
} }
private: private:

View File

@ -38,5 +38,5 @@
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same * with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
* numbers used in [SQLITECPP_VERSION]. * numbers used in [SQLITECPP_VERSION].
*/ */
#define SQLITECPP_VERSION "0.6.0" #define SQLITECPP_VERSION "0.7.0"
#define SQLITECPP_VERSION_NUMBER 0006000 #define SQLITECPP_VERSION_NUMBER 0006000