30 extern "C" bool utIsInterruptPending();
31 extern "C" bool utSetInterruptEnabled(
bool );
32 extern "C" bool utSetInterruptHandled(
bool );
60 rc = sqlite3_extended_errcode( dbid );
71 static char dummy[32];
77 case SQLITE_OK:
return(
"SQLITE:OK" );
78 case SQLITE_ERROR:
return(
"SQLITE:ERROR" );
79 case SQLITE_INTERNAL:
return(
"SQLITE:INTERNAL" );
80 case SQLITE_PERM:
return(
"SQLITE:PERM" );
81 case SQLITE_ABORT:
return(
"SQLITE:ABORT" );
82 case SQLITE_BUSY:
return(
"SQLITE:BUSY" );
83 case SQLITE_LOCKED:
return(
"SQLITE:LOCKED" );
84 case SQLITE_NOMEM:
return(
"SQLITE:NOMEM" );
85 case SQLITE_READONLY:
return(
"SQLITE:READONLY" );
86 case SQLITE_INTERRUPT:
return(
"SQLITE:INTERRUPT" );
87 case SQLITE_IOERR:
return(
"SQLITE:IOERR" );
88 case SQLITE_CORRUPT:
return(
"SQLITE:CORRUPT" );
89 case SQLITE_NOTFOUND:
return(
"SQLITE:NOTFOUND" );
90 case SQLITE_FULL:
return(
"SQLITE:FULL" );
91 case SQLITE_CANTOPEN:
return(
"SQLITE:CANTOPEN" );
92 case SQLITE_PROTOCOL:
return(
"SQLITE:PROTOCOL" );
93 case SQLITE_EMPTY:
return(
"SQLITE:EMPTY" );
94 case SQLITE_SCHEMA:
return(
"SQLITE:SCHEMA" );
95 case SQLITE_TOOBIG:
return(
"SQLITE:TOOBIG" );
96 case SQLITE_CONSTRAINT:
return(
"SQLITE:CONSTRAINT" );
97 case SQLITE_MISMATCH:
return(
"SQLITE:MISMATCH" );
98 case SQLITE_MISUSE:
return(
"SQLITE:MISUSE" );
99 case SQLITE_NOLFS:
return(
"SQLITE:NOLFS" );
100 case SQLITE_AUTH:
return(
"SQLITE:AUTH" );
101 case SQLITE_FORMAT:
return(
"SQLITE:FORMAT" );
102 case SQLITE_RANGE:
return(
"SQLITE:RANGE" );
103 case SQLITE_NOTADB:
return(
"SQLITE:NOTADB" );
104 case SQLITE_NOTICE:
return(
"SQLITE:NOTICE" );
105 case SQLITE_WARNING:
return(
"SQLITE:WARNING" );
106 case SQLITE_ROW:
return(
"SQLITE:ROW" );
107 case SQLITE_DONE:
return(
"SQLITE:DONE" );
109 case SQLITE_IOERR_READ:
return(
"SQLITE:IOERR_READ" );
110 case SQLITE_IOERR_SHORT_READ:
return(
"SQLITE:IOERR_SHORT_READ" );
111 case SQLITE_IOERR_WRITE:
return(
"SQLITE:IOERR_WRITE" );
112 case SQLITE_IOERR_FSYNC:
return(
"SQLITE:IOERR_FSYNC" );
113 case SQLITE_IOERR_DIR_FSYNC:
return(
"SQLITE:IOERR_DIR_FSYNC" );
114 case SQLITE_IOERR_TRUNCATE:
return(
"SQLITE:IOERR_TRUNCATE" );
115 case SQLITE_IOERR_FSTAT:
return(
"SQLITE:IOERR_FSTAT" );
116 case SQLITE_IOERR_UNLOCK:
return(
"SQLITE:IOERR_UNLOCK" );
117 case SQLITE_IOERR_RDLOCK:
return(
"SQLITE:IOERR_RDLOCK" );
118 case SQLITE_IOERR_DELETE:
return(
"SQLITE:IOERR_DELETE" );
119 case SQLITE_IOERR_BLOCKED:
return(
"SQLITE:IOERR_BLOCKED" );
120 case SQLITE_IOERR_NOMEM:
return(
"SQLITE:IOERR_NOMEM" );
121 case SQLITE_IOERR_ACCESS:
return(
"SQLITE:IOERR_ACCESS" );
122 case SQLITE_IOERR_CHECKRESERVEDLOCK:
return(
"SQLITE:IOERR_CHECKRESERVEDLOCK" );
123 case SQLITE_IOERR_LOCK:
return(
"SQLITE:IOERR_LOCK" );
124 case SQLITE_IOERR_CLOSE:
return(
"SQLITE:IOERR_CLOSE" );
125 case SQLITE_IOERR_DIR_CLOSE:
return(
"SQLITE:IOERR_DIR_CLOSE" );
126 case SQLITE_IOERR_SHMOPEN:
return(
"SQLITE:IOERR_SHMOPEN" );
127 case SQLITE_IOERR_SHMSIZE:
return(
"SQLITE:IOERR_SHMSIZE" );
128 case SQLITE_IOERR_SHMLOCK:
return(
"SQLITE:IOERR_SHMLOCK" );
129 case SQLITE_IOERR_SHMMAP:
return(
"SQLITE:IOERR_SHMMAP" );
130 case SQLITE_IOERR_SEEK:
return(
"SQLITE:IOERR_SEEK" );
131 case SQLITE_IOERR_DELETE_NOENT:
return(
"SQLITE:IOERR_DELETE_NOENT" );
132 case SQLITE_IOERR_MMAP:
return(
"SQLITE:IOERR_MMAP" );
133 case SQLITE_IOERR_GETTEMPPATH:
return(
"SQLITE:IOERR_GETTEMPPATH" );
134 case SQLITE_IOERR_CONVPATH:
return(
"SQLITE:IOERR_CONVPATH" );
135 case SQLITE_LOCKED_SHAREDCACHE:
return(
"SQLITE:LOCKED_SHAREDCACHE" );
136 case SQLITE_BUSY_RECOVERY:
return(
"SQLITE:BUSY_RECOVERY" );
137 case SQLITE_BUSY_SNAPSHOT:
return(
"SQLITE:BUSY_SNAPSHOT" );
138 case SQLITE_CANTOPEN_NOTEMPDIR:
return(
"SQLITE:CANTOPEN_NOTEMPDIR" );
139 case SQLITE_CANTOPEN_ISDIR:
return(
"SQLITE:CANTOPEN_ISDIR" );
140 case SQLITE_CANTOPEN_FULLPATH:
return(
"SQLITE:CANTOPEN_FULLPATH" );
141 case SQLITE_CANTOPEN_CONVPATH:
return(
"SQLITE:CANTOPEN_CONVPATH" );
142 case SQLITE_CORRUPT_VTAB:
return(
"SQLITE:CORRUPT_VTAB" );
143 case SQLITE_READONLY_RECOVERY:
return(
"SQLITE:READONLY_RECOVERY" );
144 case SQLITE_READONLY_CANTLOCK:
return(
"SQLITE:READONLY_CANTLOCK" );
145 case SQLITE_READONLY_ROLLBACK:
return(
"SQLITE:READONLY_ROLLBACK" );
146 case SQLITE_READONLY_DBMOVED:
return(
"SQLITE:READONLY_DBMOVED" );
147 case SQLITE_ABORT_ROLLBACK:
return(
"SQLITE:ABORT_ROLLBACK" );
148 case SQLITE_CONSTRAINT_CHECK:
return(
"SQLITE:CONSTRAINT_CHECK" );
149 case SQLITE_CONSTRAINT_COMMITHOOK:
return(
"SQLITE:CONSTRAINT_COMMITHOOK" );
150 case SQLITE_CONSTRAINT_FOREIGNKEY:
return(
"SQLITE:CONSTRAINT_FOREIGNKEY" );
151 case SQLITE_CONSTRAINT_FUNCTION:
return(
"SQLITE:CONSTRAINT_FUNCTION" );
152 case SQLITE_CONSTRAINT_NOTNULL:
return(
"SQLITE:CONSTRAINT_NOTNULL" );
153 case SQLITE_CONSTRAINT_PRIMARYKEY:
return(
"SQLITE:CONSTRAINT_PRIMARYKEY" );
154 case SQLITE_CONSTRAINT_TRIGGER:
return(
"SQLITE:CONSTRAINT_TRIGGER" );
155 case SQLITE_CONSTRAINT_UNIQUE:
return(
"SQLITE:CONSTRAINT_UNIQUE" );
156 case SQLITE_CONSTRAINT_VTAB:
return(
"SQLITE:CONSTRAINT_VTAB" );
157 case SQLITE_CONSTRAINT_ROWID:
return(
"SQLITE:CONSTRAINT_ROWID" );
158 case SQLITE_NOTICE_RECOVER_WAL:
return(
"SQLITE:NOTICE_RECOVER_WAL" );
159 case SQLITE_NOTICE_RECOVER_ROLLBACK:
return(
"SQLITE:NOTICE_RECOVER_ROLLBACK" );
160 case SQLITE_WARNING_AUTOINDEX:
return(
"SQLITE:WARNING_AUTOINDEX" );
161 case SQLITE_AUTH_USER:
return(
"SQLITE:AUTH_USER" );
164 _snprintf( dummy,
sizeof( dummy ),
"SQLITE:ERRNO%d", errorcode );
193 enum {FCN, STEP, FINAL};
205 for(
int i = 0; i < 3; i++ )
213 m_pexception = &exception;
228 for(
int i = 0; i < 3; i++ )
230 m_functors[i] = other.m_functors[i];
232 m_group_data = other.m_group_data;
233 m_pexception = other.m_pexception;
262 for(
int i = 0; i < 3; i++ )
270 PRINTF(
"%s\n",
"Functors destroyed" );
278 std::swap( *m_pexception, exception );
301 return m_functors[nr];
329 for(
int i = 0; i < 3; i++ )
331 if( m_functors[i].IsEmpty() )
336 if( !m_functors[i].IsFunctionHandle() || m_functors[i].NumElements() != 1 )
408 if( utIsInterruptPending() )
410 utSetInterruptHandled(
true );
421 const int N_INSTRUCTIONS = 1000;
436 if( !closeDb( err ) )
446 unsigned char* filename_utf8 = NULL;
447 int filename_utf8_bytes =
utils_latin2utf( (
const unsigned char*)filename, NULL );
449 if( filename_utf8_bytes )
451 filename_utf8 = (
unsigned char*)
MEM_ALLOC( filename_utf8_bytes,
sizeof(
char) );
456 err.
set( MSG_ERRMEMORY );
462 int rc = sqlite3_open_v2( (
char*)filename_utf8, &m_db, openFlags, NULL );
464 if( SQLITE_OK != rc )
469 sqlite3_extended_result_codes( m_db,
true );
470 attachBuiltinFunctions();
471 utSetInterruptEnabled(
true );
472 setProgressHandler(
true );
485 for( MexFunctorsMap::iterator it = m_fcnmap.begin(); it != m_fcnmap.end(); it++ )
492 int rc = sqlite3_close( m_db );
493 if( SQLITE_OK == rc )
534 sqlite3_create_function( m_db,
"pow", 2, SQLITE_UTF8, NULL,
pow_func, NULL, NULL );
535 sqlite3_create_function( m_db,
"lg", 1, SQLITE_UTF8, NULL,
lg_func, NULL, NULL );
536 sqlite3_create_function( m_db,
"ln", 1, SQLITE_UTF8, NULL,
ln_func, NULL, NULL );
537 sqlite3_create_function( m_db,
"exp", 1, SQLITE_UTF8, NULL,
exp_func, NULL, NULL );
538 sqlite3_create_function( m_db,
"regex", 2, SQLITE_UTF8, NULL,
regex_func, NULL, NULL );
539 sqlite3_create_function( m_db,
"regex", 3, SQLITE_UTF8, NULL,
regex_func, NULL, NULL );
540 sqlite3_create_function( m_db,
"bdcratio", 1, SQLITE_UTF8, NULL,
BDC_ratio_func, NULL, NULL );
541 sqlite3_create_function( m_db,
"bdcpacktime", 1, SQLITE_UTF8, NULL,
BDC_pack_time_func, NULL, NULL );
542 sqlite3_create_function( m_db,
"bdcunpacktime", 1, SQLITE_UTF8, NULL,
BDC_unpack_time_func, NULL, NULL );
543 sqlite3_create_function( m_db,
"md5", 1, SQLITE_UTF8, NULL,
MD5_func, NULL, NULL );
571 m_pstackitem( &stackitem ),
572 m_db( stackitem.dbid() ),
577 sqlite3_initialize();
603 const char*
getErr(
const char** errid = NULL )
605 return m_lasterr.
get( errid );
612 m_lasterr.
set( err_id );
639 return sqlite3_db_filename( m_db, database ? database :
"MAIN" );
652 int rc = sqlite3_busy_timeout( m_db, iTimeoutValue );
653 if( SQLITE_OK != rc )
671 int rc = sqlite3_busy_timeout( m_db, iTimeoutValue );
672 if( SQLITE_OK != rc )
690 int rc = sqlite3_enable_load_extension( m_db, flagOnOff != 0 );
691 if( SQLITE_OK != rc )
706 sqlite3_clear_bindings( m_stmt );
707 sqlite3_reset( m_stmt );
708 sqlite3_finalize( m_stmt );
719 mexFcnWrapper( ctx, argc, argv, MexFunctors::FCN );
726 mexFcnWrapper( ctx, argc, argv, MexFunctors::STEP );
733 mexFcnWrapper( ctx, 0, NULL, MexFunctors::FINAL );
738 void mexFcnWrapper( sqlite3_context *ctx,
int argc, sqlite3_value **argv,
int func_nr )
741 int nArgs = argc + 1 + (func_nr > MexFunctors::FCN);
745 assert( fcn && arg.Item() );
750 sqlite3_result_error( ctx, ::
getLocaleMsg( MSG_INVALIDFUNCTION ), -1 );
757 sqlite3_result_error( ctx, ::
getLocaleMsg( MSG_RECURSIVECALL ), -1 );
762 for(
int j = 0; j < nArgs && !failed; j++ )
764 int err_id = MSG_NOERROR;
776 if( func_nr > MexFunctors::FCN )
787 switch( sqlite3_value_type( argv[i] ) )
793 value =
ValueSQL( sqlite3_value_int64( argv[i] ) );
797 value =
ValueSQL( sqlite3_value_double( argv[i] ) );
813 size_t bytes = sqlite3_value_bytes( argv[i] );
815 item =
ValueMex( (
int)bytes, bytes ? 1 : 0, ValueMex::UINT8_CLASS );
821 memcpy( item.
Data(), sqlite3_value_blob( argv[i] ), bytes );
828 sqlite3_result_error( ctx,
getLocaleMsg( MSG_ERRMEMORY ), -1 );
836 sqlite3_result_error( ctx,
getLocaleMsg( MSG_UNKNWNDBTYPE ), -1 );
849 if( MSG_NOERROR != err_id )
851 sqlite3_result_error( ctx, ::
getLocaleMsg( err_id ), -1 );
861 arg.Call( &item, &exception );
868 sqlite3_result_error( ctx,
"MATLAB Exception!", -1 );
873 if( func_nr == MexFunctors::STEP )
878 std::swap( fcn->
getData(), item );
881 sqlite3_result_null( ctx );
888 int err_id = MSG_NOERROR;
892 if( MSG_NOERROR != err_id )
896 sqlite3_result_error( ctx, err.
get(), -1 );
903 sqlite3_result_null( ctx );
908 sqlite3_result_double( ctx, item.
GetScalar() );
912 if( (
int)item.
ClassID() == (int)ValueMex::INT64_CLASS )
915 sqlite3_result_int64( ctx, item.
GetInt64() );
920 sqlite3_result_int( ctx, item.
GetInt() );
927 sqlite3_result_text( ctx, value.m_text, -1, SQLITE_TRANSIENT );
932 sqlite3_result_blob( ctx, item.
Data(),
940 sqlite3_result_blob( ctx, value.
Detach(),
949 err.
set( MSG_INVALIDARG );
950 sqlite3_result_error( ctx, err.
get(), - 1 );
958 sqlite3_result_null( ctx );
969 if( func_nr == MexFunctors::FINAL )
995 rc = sqlite3_create_function( m_db, name, -1, SQLITE_UTF8, NULL, NULL, NULL, NULL );
1002 setErr( MSG_FCNHARGEXPCT );
1008 void (*xFunc)(sqlite3_context*,int,sqlite3_value**) = mexFcnWrapper_FCN;
1009 void (*xStep)(sqlite3_context*,int,sqlite3_value**) = mexFcnWrapper_STEP;
1010 void (*xFinal)(sqlite3_context*) = mexFcnWrapper_FINAL;
1016 rc = sqlite3_create_function( m_db, name, -1, SQLITE_UTF8, (
void*)fcn, xFunc, xStep, xFinal );
1021 if( SQLITE_OK != rc )
1031 if( m_pstackitem->
fcnmap().count(name) )
1034 PRINTF(
"Deleting functors for %s\n", name );
1036 delete m_pstackitem->
fcnmap()[name];
1037 m_pstackitem->
fcnmap().erase(name);
1043 m_pstackitem->
fcnmap()[name] = fcn;
1050 return !errPending();
1074 if( !sqlite3_complete( query ) )
1076 setErr( MSG_INVQUERY );
1087 int rc = sqlite3_prepare_v2( m_db, query, -1, &m_stmt, 0 );
1088 if( SQLITE_OK != rc )
1102 return m_stmt ? sqlite3_bind_parameter_count( m_stmt ) : 0;
1108 return m_stmt ? sqlite3_bind_parameter_name( m_stmt, n ) : NULL;
1114 return m_stmt ? (long)sqlite3_last_insert_rowid(m_db) : 0;
1123 sqlite3_clear_bindings( m_stmt );
1137 int err_id = MSG_NOERROR;
1138 int iTypeComplexity;
1145 if( MSG_NOERROR != err_id )
1154 rc = sqlite3_bind_null( m_stmt, index );
1155 if( SQLITE_OK != rc )
1163 rc = sqlite3_bind_double( m_stmt, index, item.
GetScalar() );
1164 if( SQLITE_OK != rc )
1170 case SQLITE_INTEGER:
1171 if( (
int)item.
ClassID() == (int)ValueMex::INT64_CLASS )
1174 rc = sqlite3_bind_int64( m_stmt, index, item.
GetInt64() );
1175 if( SQLITE_OK != rc )
1183 rc = sqlite3_bind_int( m_stmt, index, item.
GetInt() );
1184 if( SQLITE_OK != rc )
1194 rc = sqlite3_bind_text( m_stmt, index, value.m_text, -1, SQLITE_TRANSIENT );
1195 if( SQLITE_OK != rc )
1203 rc = sqlite3_bind_blob( m_stmt, index, item.
Data(),
1206 if( SQLITE_OK != rc )
1215 rc = sqlite3_bind_blob( m_stmt, index, value.
Detach(),
1218 if( SQLITE_OK != rc )
1226 setErr( MSG_INVALIDARG );
1230 return !errPending();
1237 return m_stmt ? sqlite3_step( m_stmt ) : SQLITE_ERROR;
1244 return m_stmt ? sqlite3_column_count( m_stmt ) : 0;
1256 return m_stmt ? sqlite3_column_type( m_stmt, index ) : -1;
1263 return m_stmt ? sqlite3_column_int64( m_stmt, index ) : 0;
1270 return m_stmt ? sqlite3_column_double( m_stmt, index ) : 0.0;
1277 return m_stmt ? sqlite3_column_text( m_stmt, index ) : (
const unsigned char*)
"";
1284 unsigned char* test = (
unsigned char*)sqlite3_column_blob( m_stmt, index );
1285 return m_stmt ? sqlite3_column_blob( m_stmt, index ) : NULL;
1292 return m_stmt ? sqlite3_column_bytes( m_stmt, index ) : 0;
1299 return m_stmt ? sqlite3_column_name( m_stmt, index ) :
"";
1309 if( a >=
'a' && a <=
'z' )
return a;
1310 if( a >=
'A' && a <=
'Z' )
return a;
1311 if( a >=
'0' && a <=
'9' )
return a;
1335 for(
int i = 0; i < colCount(); i++ )
1337 pair<string,string> item( colName(i), colName(i) );
1343 std::transform( item.second.begin(), item.second.end(), item.second.begin(),
to_alphanum() );
1346 if( !item.second.size() || !isalpha(item.second[0]) )
1348 item.second = string(
"X") + item.second;
1356 string new_name(item.second);
1359 while( loop < i && number < 100 )
1362 if( new_name == names[loop].second )
1369 str_number_len = _snprintf( str_number,
g_namelengthmax+1,
"_%d", number );
1374 delete[] str_number;
1387 setErr( MSG_ERRVARNAME );
1391 item.second = new_name;
1394 names.push_back( item );
1397 return (
int)names.size();
1406 sqlite3_reset( m_stmt );
1416 sqlite3_clear_bindings( m_stmt );
1417 sqlite3_finalize( m_stmt );
1440 getColNames( names );
1444 for(
int i = 0; i < (int)names.size(); i++ )
1453 for( ; !errPending() ; )
1458 int step_res = step();
1460 if (step_res == SQLITE_DONE)
1466 if (step_res != SQLITE_ROW)
1475 for(
int jCol = 0; jCol < (int)cols.size() && !errPending(); jCol++ )
1480 switch( colType( jCol ) )
1485 case SQLITE_INTEGER:
1486 value =
ValueSQL( colInt64( jCol ) );
1490 value =
ValueSQL( colFloat( jCol ) );
1499 size_t bytes = colBytes( jCol );
1501 ValueMex item =
ValueMex( (
int)bytes, bytes ? 1 : 0, ValueMex::UINT8_CLASS );
1507 memcpy( item.
Data(), colBlob( jCol ), bytes );
1512 setErr( MSG_ERRMEMORY );
1521 setErr( MSG_UNKNWNDBTYPE );
1525 cols[jCol].append( value );
bool setEnableLoadExtension(int flagOnOff)
Enable or disable load extensions.
Encapsulating a MATLAB mxArray.
void throwOnException()
(Re-)Throws an exception, if any occurred
size_t m_blobsize
Size of BLOB in bytes (only type SQLITE_BLOBX)
Class holding an exception array, the function map and the handle for one database.
int getParameterCount()
Returns the count of parameters the current statement expects.
bool isOpen()
Returns true, if database is opened.
void clearErr()
Clear recent error message.
MexFunctorsMap m_fcnmap
MEX function map with MATLAB functions for application-defined SQL functions.
const char * getErr(const char **errid=NULL)
Get recent error message.
static void mexFcnWrapper(sqlite3_context *ctx, int argc, sqlite3_value **argv, int func_nr)
Common wrapper for all user defined SQL functions.
void setErr(int err_id)
Sets an error by its ID (see MSG_IDS)
void ln_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Natural logarithm function implementation.
bool isOpen()
Returns true, if database is open.
void set_printf(int iMessageNr, const char *strId,...)
Set error message by identifier (translations available) with printf arguments.
MexFunctors(MexFunctors &&other)
Move Ctor.
mxClassID ClassID() const
Returns item class ID or mxUNKNOWN_CLASS if item is NULL.
ValueMex m_group_data
Data container for "step" and "final" functions.
MexFunctors()
inhibit standard Ctor
void swapException(ValueMex &exception)
Exchange exception stack information.
ValueMex createItemFromValueSQL(const ValueSQL &value, int &err_id)
Transfer fetched SQL value into MATLAB array.
bool closeDb(SQLerror &err)
Close database.
bool checkFunc(int nr) const
Check if function handle is valid (not empty and of functon handle class)
void closeStmt()
Closing current statement.
ValueMex * m_pexception
Exception stack information.
static ValueMex CreateCellMatrix(int m, int n)
Create a cell array.
ValueMex Duplicate() const
Returns a duplictae of the hosted MATLAB array.
bool IsEmpty() const
Check if one of the functors is empty.
void BDC_pack_time_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
BDCPackTime function implementation.
int colType(int index)
Returns the (prefered) type of one column for current statement.
const char * getParameterName(int n)
Returns the name for nth parameter.
int GetInt(int errval=0) const
Get integer value from item.
int m_typeID
Type of SQL value as integer ID.
SQLstackitem * m_pstackitem
pointer to current database
bool fetch(ValueSQLCols &cols, bool initialize=false)
Proceed a table fetch.
const char * getLocaleMsg(int iMsgNr)
Returns the translation for a defined message.
void MakePersistent()
Make the MATLAB array persistent.
void Destroy()
Freeing memory space if having ownership.
const unsigned char * colText(int index)
Returns a text value for least fetch and column number.
mxArray * Detach()
Detach hosted MATLAB array.
static int progressHandler(void *data)
Progress handler (watchdog)
bool setQuery(const char *query)
Dispatch a SQL query.
MexFunctors & operator=(const MexFunctors &other)
Copy assignment.
void initGroupData()
Initialize data for "step" and "final" function.
void attachBuiltinFunctions()
Attach builtin functions to database object.
bool attachMexFunction(const char *name, const ValueMex &func, const ValueMex &step, const ValueMex &final, ValueMex &exception)
Attach application-defined function to database object.
const char * getDbFilename(const char *database)
Get the filename of current database.
double colFloat(int index)
Returns a floating point value for least fetch and column number.
const ValueMex & getFunc(int nr) const
Return one of the functors (function, init or final)
sqlite3 * m_db
SQLite db handle.
void clearBindings()
Clears all parameter bindings from current statement.
ValueMex dupFunc(int nr) const
Duplicate one of the functors (function, init or final)
size_t ByData() const
Returns data size in bytes.
void finalize()
Clear parameter bindings and finalize current statement.
void regex_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Regular expression function implementation.
sqlite3_int64 GetInt64(int errval=0) const
Get 64 bit integer value from item.
const char * m_command
SQL query (no ownership, read-only!)
Class encapsulating a SQL field value.
MexFunctors(ValueMex &exception, const ValueMex &func, const ValueMex &step, const ValueMex &final)
Ctor.
MexFunctors(const MexFunctors &other)
Copy Ctor.
bool isPending()
Returns true, if the current error message is still not handled.
#define MEM_FREE(ptr)
standard memory free function
ValueMex m_exception
MATALAB exception array, may be thrown when mksqlite function leaves.
const void * colBlob(int index)
Returns a BLOB for least fetch and column number.
void clear()
Reset error message.
sqlite3_stmt * m_stmt
SQL statement (sqlite bridge)
MexFunctors(MexFunctors &other)
Copy Ctor.
void MD5_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
MD5 hashing implementation.
char operator()(char a)
Functor.
int g_namelengthmax
MATALAB specific globals.
bool can_serialize()
Returns true, if streaming is switched on (user setting) and serialization is accessible.
Helperclass for error message transport.
bool errPending()
Returns true, if an unhandled error is pending.
bool m_busy
true, if function is in progress to prevent recursive calls
MexFunctorsMap & fcnmap()
Returns the function map for this database.
bool IsEmpty() const
Returns true if item is NULL or empty ([])
int g_convertUTF8
Flag: String representation (utf8 or ansi)
vector< ValueSQLCol > ValueSQLCols
type for column container
sqlite3_int64 colInt64(int index)
Returns an integer value for least fetch and column number.
size_t colBytes(int index)
Returns the size of one value of least fetch and column number in bytes.
Converts one char to a printable (non-white-space) character.
static void mexFcnWrapper_STEP(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Wrapper for SQL step function (aggregation)
void set(const char *strMsg, const char *strId=NULL)
Set error message to a constant string (without translation)
ValueMex & getException()
Returns the exception array for this database.
void * Data() const
Returns pointer to raw data.
bool IsFunctionHandle() const
Returns true if m_pcItem is of type mxFUNCTION_CLASS.
bool openDb(const char *filename, int openFlags, SQLerror &err)
Opens (or create) database.
static void mexFcnWrapper_FCN(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Wrapper for SQL function.
#define SQLITE_BLOBX
Identifier to flag another allocator as used for SQLITE_BLOB.
map< string, MexFunctors * > MexFunctorsMap
Dictionary: function name => function handles.
char * utils_strnewdup(const char *s, int flagConvertUTF8)
duplicate a string and recode from UTF8 to char due to flag flagConvertUTF8
int utils_latin2utf(const unsigned char *s, unsigned char *buffer)
Convert char string to UTF-8 string.
int colCount()
Returns the column count for current statement.
Functors for SQL application-defined (aggregation) functions.
void setSqlError(sqlite3 *dbid, int rc)
Set error by its result code.
void pow_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Power function implementation.
bool setBusyTimeout(int iTimeoutValue)
Sets the busy timemout in milliseconds.
Class encapsulating a complete SQL table column with type and name.
void BDC_unpack_time_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
BDCUnpackTime function implementation.
void Throw()
Throws an exception if any occured.
const char * trans_err_to_ident(int errorcode)
Get least SQLite error code and return identifier as string.
const mxArray * Item() const
Returns hosted MATLAB array.
void lg_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Logarithm function to base 10 implementation.
void exp_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
Exponential function implementation.
bool bindParameter(int index, const ValueMex &item, bool bStreamable)
Binds one parameter from current statement to a MATLAB array.
void setProgressHandler(bool enable=true)
Installing progress handler to enable aborting by Ctrl+C.
const char * get(const char **errId=NULL)
Get the current error message.
void setSqlError(int rc)
Sets an error by its SQL return code.
void BDC_ratio_func(sqlite3_context *ctx, int argc, sqlite3_value **argv)
BDCRatio function implementation.
void reset()
Reset current SQL statement.
int getColNames(ValueSQLCol::StringPairList &names)
Returns the column names of least fetch.
void SetCell(int i, const mxArray *cell)
Sets a cell of a MATLAB cell array.
long getLastRowID()
kv69: Returns the number of last row id; usefull for inserts in tables with autoincrement primary key...
static void mexFcnWrapper_FINAL(sqlite3_context *ctx)
Wrapper for SQL final function (aggregation)
ValueSQL createValueSQLFromItem(const ValueMex &item, bool bStreamable, int &iTypeComplexity, int &err_id)
Transfer MATLAB array into a SQL value.
SQL builtin functions, automatically attached to each database.
SQLiface(SQLstackitem &stackitem)
Standard ctor.
bool getBusyTimeout(int &iTimeoutValue)
Returns the busy timeout in milliseconds.
ValueMex & getData()
Return data array from "step" and "final" function.
MexFunctors & operator=(MexFunctors &&other)
Move assignment.
int step()
Evaluates current SQL statement.
#define PRINTF
Global text output function.
void * Detach()
Release custody and return pointer type.
sqlite3 * m_db
SQLite db object.
vector< StringPair > StringPairList
list of string pairs
const char * colName(int index)
Returns the column name least fetch and column number.
SQLerror m_lasterr
recent error message
#define MEM_ALLOC(count, bytes)
standard memory allocator
int g_check4uniquefields
Flag: Check for unique fieldnames.
bool IsValid() const
Check if all functors are valid.