mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-05 02:06:02 -04:00
added wrapper for sqlite3_create_function_v2
This commit is contained in:
parent
bac9020ba0
commit
de04b3c2e8
@ -14,6 +14,9 @@
|
|||||||
#include "Assertion.h"
|
#include "Assertion.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
|
||||||
|
#ifndef SQLITE_DETERMINISTIC
|
||||||
|
#define SQLITE_DETERMINISTIC 0x800
|
||||||
|
#endif //SQLITE_DETERMINISTIC
|
||||||
|
|
||||||
namespace SQLite
|
namespace SQLite
|
||||||
{
|
{
|
||||||
@ -97,5 +100,20 @@ void Database::check(const int aRet) const // throw(SQLite::Exception)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach a custom function to your sqlite database.
|
||||||
|
// assumes UTF8 text representation.
|
||||||
|
// 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 *))
|
||||||
|
{
|
||||||
|
int eTextRep = SQLITE_UTF8;
|
||||||
|
// optimization if deterministic function... e.g. of non deterministic function (random())
|
||||||
|
if (deterministic) {
|
||||||
|
eTextRep = eTextRep|SQLITE_DETERMINISTIC;
|
||||||
|
}
|
||||||
|
int ret = sqlite3_create_function_v2(mpSQLite, funcName, nArg, eTextRep, pApp, xFunc, xStep, xFinal, xDestroy);
|
||||||
|
|
||||||
|
check(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace SQLite
|
} // namespace SQLite
|
||||||
|
@ -230,6 +230,50 @@ public:
|
|||||||
return sqlite3_errmsg(mpSQLite);
|
return sqlite3_errmsg(mpSQLite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a function in the sqlite database.
|
||||||
|
*
|
||||||
|
* This is the equivalent of the sqlite3_create_function_v2 command.
|
||||||
|
* NOTE: UTF-8 text encoding assumed.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param[in] funcName Name of the SQL function to be created or redefined
|
||||||
|
* @param[in] nArg Number of arguments in the function
|
||||||
|
* @param[in] determininistic optimize for deterministic functions. Most sqlite functions are deterministic.
|
||||||
|
* a random number generator is an example of an indeterministic function.
|
||||||
|
* @param[in] pApp See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xFunc See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xStep See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xFinal See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xDestroy See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
*
|
||||||
|
* @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 *));
|
||||||
|
/**
|
||||||
|
* @brief Create a function in the sqlite database.
|
||||||
|
*
|
||||||
|
* This is the equivalent of the sqlite3_create_function_v2 command.
|
||||||
|
* NOTE: UTF-8 text encoding assumed.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param[in] funcName Name of the SQL function to be created or redefined
|
||||||
|
* @param[in] nArg Number of arguments in the function
|
||||||
|
* @param[in] determininistic optimize for deterministic functions. Most sqlite functions are deterministic.
|
||||||
|
* a random number generator is an example of an indeterministic function.
|
||||||
|
* @param[in] pApp See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xFunc See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xStep See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xFinal See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
* @param[in] xDestroy See: http://www.sqlite.org/c3ref/create_function.html
|
||||||
|
*
|
||||||
|
* @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 *))
|
||||||
|
{
|
||||||
|
return createFunction(funcName.c_str(), nArg, deterministic, pApp, xFunc, xStep, xFinal, xDestroy);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @{ Database must be non-copyable
|
/// @{ Database must be non-copyable
|
||||||
Database(const Database&);
|
Database(const Database&);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user