mksqlite  2.5
A MATLAB interface to SQLite
Public Types | Public Member Functions | Private Attributes | List of all members
Mksqlite Class Reference

Main routine class. More...

+ Collaboration diagram for Mksqlite:

Public Types

enum  command_e {
  OPEN, CLOSE, QUERY, DONE,
  FAILED
}
 Return values of cmdAnalyseCommand()
 

Public Member Functions

 Mksqlite (int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
 Standard ctor.
 
void Release ()
 Release object.
 
 ~Mksqlite ()
 Dtor.
 
bool errPending ()
 Returns true, if any error is pending.
 
void errClear ()
 Clear recent error.
 
void returnWithError ()
 Terminate function. More...
 
bool ensureDbIsOpen ()
 Ensuring current database is open. More...
 
bool warnOnDefDbid ()
 Omits a warning if database is given but superfluous. More...
 
bool assureSQLinterface ()
 Creates a SQL interface if not already happen.
 
bool argGetNextInteger (int &refValue, bool asBoolInt=false)
 Get next integer from argument list. More...
 
bool argGetNextFcnHandle (const mxArray *&refValue)
 Get next value as function handle from argument list. More...
 
bool argGetNextLiteral (const mxArray *&refValue)
 Get next value as literal argument from argument list. More...
 
bool argTryReadValidDbid ()
 Get database ID from argument list. More...
 
bool argReadCommand ()
 Get command from argument list. More...
 
bool cmdTryHandleFlag (const char *strMatchFlagName, int &refFlag)
 Handle flag from command. More...
 
bool cmdTryHandleVersion (const char *strCmdMatchVerMex, const char *strCmdMatchVerSql)
 Handle version commands. More...
 
bool cmdTryHandleTypedBlob (const char *strCmdMatchName)
 Handle typed BLOB settings command. More...
 
bool cmdTryHandleEnableExtension (const char *strCmdMatchName)
 Handle command to (en-/dis-)able loading extensions. More...
 
bool cmdTryHandleCreateFunction (const char *strCmdMatchName)
 Handle command to create or delete a SQL user function. More...
 
bool cmdTryHandleCreateAggregation (const char *strCmdMatchName)
 Handle command to create or delete a SQL user aggregate function. More...
 
bool cmdTryHandleCompression (const char *strCmdMatchName)
 Handle compression setting command. More...
 
bool cmdTryHandleStatus (const char *strCmdMatchName)
 Handle status command. More...
 
bool cmdTryHandleLanguage (const char *strCmdMatchName)
 Handle language command. More...
 
bool cmdTryHandleFilename (const char *strCmdMatchName)
 Get the filename of current database. More...
 
bool cmdTryHandleStreaming (const char *strCmdMatchName)
 Handle streaming setting command. More...
 
bool cmdTryHandleResultType (const char *strCmdMatchName)
 Handle result type command. More...
 
bool cmdTryHandleSetBusyTimeout (const char *strCmdMatchName)
 Handle set busy timeout command. More...
 
bool cmdTryHandleNonSqlStatement ()
 Interpret current argument as command or switch. More...
 
command_e cmdAnalyseCommand ()
 Analyse command string and process if its neither open, close nor a sql command. More...
 
bool cmdHandleOpen ()
 Handle open command. More...
 
bool cmdHandleClose ()
 Handle close command. More...
 
ValueMex createItemFromValueSQL (const ValueSQL &value)
 Transfer fetched SQL value into a MATLAB array. More...
 
mxArray * createResultColNameMatrix (const ValueSQLCols &cols)
 Create a MATLAB cell array of column names. More...
 
mxArray * createResultAsArrayOfStructs (ValueSQLCols &cols)
 Transform SQL fetch to MATLAB array of structs. More...
 
mxArray * createResultAsStructOfArrays (ValueSQLCols &cols)
 Transform SQL fetch to MATLAB struct of arrays. More...
 
mxArray * createResultAsMatrix (ValueSQLCols &cols)
 Transform SQL fetch to MATLAB (cell) array. More...
 
bool cmdHandleSQLStatement ()
 Handle common SQL statement. More...
 
bool switchDBSlot (command_e command)
 Selects the desired slot from SQLStack for the operation. More...
 
void cmdExecute ()
 Execute the command string passed to mksqlite.
 

Private Member Functions

Inhibit assignment, default and copy ctors
 Mksqlite ()
 
 Mksqlite (const Mksqlite &)
 
Mksqliteoperator= (const Mksqlite &)
 

Private Attributes

int m_nlhs
 count of left hand side arguments
 
int m_narg
 count of right hand side arguments
 
mxArray ** m_plhs
 pointer to current left hand side argument
 
const mxArray ** m_parg
 pointer to current right hand side argument
 
char * m_command
 SQL command. Allocated and freed by this class.
 
const char * m_query
 m_command, or a translation from m_command
 
int m_dbid_req
 requested database id (user input) -1="arg missing", 0="next free slot" or 1..COUNT_DB
 
int m_dbid
 selected database slot (1..COUNT_DB)
 
SQLerror m_err
 recent error
 
SQLifacem_interface
 interface (holding current SQLite statement) to current database
 

Detailed Description

Main routine class.

Definition at line 478 of file mksqlite.cpp.

Member Function Documentation

◆ argGetNextFcnHandle()

bool Mksqlite::argGetNextFcnHandle ( const mxArray *&  refValue)
inline

Get next value as function handle from argument list.

Parameters
[out]refValueResult will be returned in

Read next parameter at current argument read position, and write to refValue

Definition at line 665 of file mksqlite.cpp.

References Err::set().

◆ argGetNextInteger()

bool Mksqlite::argGetNextInteger ( int &  refValue,
bool  asBoolInt = false 
)
inline

Get next integer from argument list.

Parameters
[out]refValueResult will be returned in
[in]asBoolIntIf true, refValue will be true (1) or false (0) only

Read an integer parameter at current argument read position, and write to refValue (as 0 or 1 if asBoolInt is set to true)

Definition at line 629 of file mksqlite.cpp.

References Err::set().

◆ argGetNextLiteral()

bool Mksqlite::argGetNextLiteral ( const mxArray *&  refValue)
inline

Get next value as literal argument from argument list.

Parameters
[out]refValueResult will be returned in

Read next parameter at current argument read position, and write to refValue

Definition at line 697 of file mksqlite.cpp.

References Err::set().

◆ argReadCommand()

bool Mksqlite::argReadCommand ( )
inline

Get command from argument list.

Read the command from current argument position, always a string and thus asserted.

Definition at line 774 of file mksqlite.cpp.

References getLocaleMsg(), and PRINTF.

◆ argTryReadValidDbid()

bool Mksqlite::argTryReadValidDbid ( )
inline

Get database ID from argument list.

Reads the next argument if it is numeric and a valid dbid. dbid must be in range 0..CONFIG_MAX_NUM_OF_DBS, where 0 has the special meaning that the first free slot will later be used.
If the parameter is missing, m_dbid_req will be set to -1. m_dbid will be set to either -1 (argument missing) or a valid dbid 1..CONFIG_MAX_NUM_OF_DBS

Definition at line 729 of file mksqlite.cpp.

References SQLstack::isValidId(), and Err::set().

◆ cmdAnalyseCommand()

command_e Mksqlite::cmdAnalyseCommand ( )
inline

Analyse command string and process if its neither open, close nor a sql command.

Returns
Status (see command_e)

Reads the command from the current argument position and test for switches or other commands. Switches were dispatched, other commands remain unhandled here.

Definition at line 1745 of file mksqlite.cpp.

References STRMATCH.

◆ cmdHandleClose()

bool Mksqlite::cmdHandleClose ( )
inline

Handle close command.

Returns
true if no error occured

Closes a database. If a dbid of 0 is given, all open dbs will be closed.

Definition at line 1897 of file mksqlite.cpp.

References Err::set().

◆ cmdHandleOpen()

bool Mksqlite::cmdHandleOpen ( )
inline

Handle open command.

Handle the open command. If the read dbid is -1 a new slot (dbid) will be used, otherwise the given dbid or, if no dbid was given, the recent dbid is used.

Definition at line 1763 of file mksqlite.cpp.

References Err::set().

◆ cmdHandleSQLStatement()

bool Mksqlite::cmdHandleSQLStatement ( )
inline

Handle common SQL statement.

Returns
true when SQLite accepted and proceeded the command.

The mksqlite command string will be delegated to the SQLite engine.

Definition at line 2222 of file mksqlite.cpp.

References MEM_ALLOC, Err::set(), and utils_latin2utf().

◆ cmdTryHandleCompression()

bool Mksqlite::cmdTryHandleCompression ( const char *  strCmdMatchName)
inline

Handle compression setting command.

Parameters
[in]strCmdMatchNameCommand name
Returns
true on success

Try to interpret current command as compression setting. strCmdMatchName holds the mksqlite command name. m_plhs[0] will be set to the old setting.

Definition at line 1197 of file mksqlite.cpp.

References STRMATCH.

◆ cmdTryHandleCreateAggregation()

bool Mksqlite::cmdTryHandleCreateAggregation ( const char *  strCmdMatchName)
inline

Handle command to create or delete a SQL user aggregate function.

Parameters
[in]strCmdMatchNameCommand name

Try to interpret current command as to create a SQL user aggregate function strCmdMatchName holds the mksqlite command name.

Definition at line 1116 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleCreateFunction()

bool Mksqlite::cmdTryHandleCreateFunction ( const char *  strCmdMatchName)
inline

Handle command to create or delete a SQL user function.

Parameters
[in]strCmdMatchNameCommand name

Try to interpret current command as to create a SQL user function strCmdMatchName holds the mksqlite command name.

Definition at line 1044 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleEnableExtension()

bool Mksqlite::cmdTryHandleEnableExtension ( const char *  strCmdMatchName)
inline

Handle command to (en-/dis-)able loading extensions.

Parameters
[in]strCmdMatchNameCommand name

Try to interpret current command as setting for sqlite extension enable strCmdMatchName holds the mksqlite command name.

Definition at line 993 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleFilename()

bool Mksqlite::cmdTryHandleFilename ( const char *  strCmdMatchName)
inline

Get the filename of current database.

Parameters
strCmdMatchNameCommand name
Returns
true on success

filename will be given in m_plhs[0]

Definition at line 1407 of file mksqlite.cpp.

References Err::set(), STRMATCH, and SQLstack::switchTo().

◆ cmdTryHandleFlag()

bool Mksqlite::cmdTryHandleFlag ( const char *  strMatchFlagName,
int &  refFlag 
)
inline

Handle flag from command.

Parameters
[in]strMatchFlagNameName of flag to test
[out]refFlagFlag value if name matched
Returns
true, if flag could be assigned

Test current command as flag parameter with it's new value. strMatchFlagName holds the name of the flag to test.

Definition at line 815 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleLanguage()

bool Mksqlite::cmdTryHandleLanguage ( const char *  strCmdMatchName)
inline

Handle language command.

Parameters
[in]strCmdMatchNameCommand name
Returns
true on success

Try to interpret current command as status command. strCmdMatchName holds the mksqlite command name.

Definition at line 1357 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleNonSqlStatement()

bool Mksqlite::cmdTryHandleNonSqlStatement ( )
inline

Interpret current argument as command or switch.

Checking following commands:

  • version mex
  • version sql
  • check4uniquefields
  • convertUTF8
  • typedBLOBs
  • NULLasNaN
  • param_wrapping
  • streaming
  • result_type
  • compression
  • compression_check
  • show tables
  • enable extension
  • status
  • setbusytimeout

Definition at line 1695 of file mksqlite.cpp.

References g_check4uniquefields, g_convertUTF8, and g_NULLasNaN.

◆ cmdTryHandleResultType()

bool Mksqlite::cmdTryHandleResultType ( const char *  strCmdMatchName)
inline

Handle result type command.

Parameters
[in]strCmdMatchNameCommand name
Returns
true on success

Try to interpret current command as result type. strCmdMatchName holds the mksqlite command name. m_plhs[0] will be set to the old setting.

Definition at line 1538 of file mksqlite.cpp.

References g_result_type, Err::set(), and STRMATCH.

◆ cmdTryHandleSetBusyTimeout()

bool Mksqlite::cmdTryHandleSetBusyTimeout ( const char *  strCmdMatchName)
inline

Handle set busy timeout command.

Parameters
[in]strCmdMatchNameCommand name

Try to interpret current command as busy timeout switch. strCmdMatchName holds the mksqlite command name. m_plhs[0] will be set to the old setting.

Definition at line 1611 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleStatus()

bool Mksqlite::cmdTryHandleStatus ( const char *  strCmdMatchName)
inline

Handle status command.

Parameters
[in]strCmdMatchNameCommand name
Returns
true on success

Try to interpret current command as status command. strCmdMatchName holds the mksqlite command name.

Definition at line 1299 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleStreaming()

bool Mksqlite::cmdTryHandleStreaming ( const char *  strCmdMatchName)
inline

Handle streaming setting command.

Parameters
[in]strCmdMatchNameCommand name
Returns
true on success

Try to interpret current command as streaming switch. strCmdMatchName holds the mksqlite command name. m_plhs[0] will be set to the old setting.

Definition at line 1475 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ cmdTryHandleTypedBlob()

bool Mksqlite::cmdTryHandleTypedBlob ( const char *  strCmdMatchName)
inline

Handle typed BLOB settings command.

Parameters
[in]strCmdMatchNameCommand name
Returns
true on success

Try to interpret current command as blob mode setting strCmdMatchName hold the mksqlite command name. m_plhs[0] will be set to the old setting.

Definition at line 922 of file mksqlite.cpp.

References g_streaming, Err::set(), STRMATCH, and typed_blobs_mode_on().

◆ cmdTryHandleVersion()

bool Mksqlite::cmdTryHandleVersion ( const char *  strCmdMatchVerMex,
const char *  strCmdMatchVerSql 
)
inline

Handle version commands.

Parameters
[in]strCmdMatchVerMexCommand name to get mex version
[in]strCmdMatchVerSqlCommand name to get SQLite version
Returns
true on success

Test current command as version query to sqlite or mksqlite version numbers. strCmdMatchVerMex and strCmdMatchVerSql hold the mksqlite command names. m_plhs[0] will be set to the corresponding version string.

Definition at line 857 of file mksqlite.cpp.

References Err::set(), and STRMATCH.

◆ createItemFromValueSQL()

ValueMex Mksqlite::createItemFromValueSQL ( const ValueSQL value)
inline

Transfer fetched SQL value into a MATLAB array.

Parameters
[in]valueencapsulated SQL field value
Returns
a MATLAB array due to value type (string or numeric content)
See also
g_result_type

Definition at line 1939 of file mksqlite.cpp.

◆ createResultAsArrayOfStructs()

mxArray* Mksqlite::createResultAsArrayOfStructs ( ValueSQLCols cols)
inline

Transform SQL fetch to MATLAB array of structs.

Parameters
[in]colscontainer for SQLite fetched table
Returns
a MATLAB array of structs. The array size is the row count of the table, that cols holds. The struct field names are the column names, and may be modified due to MATLAB naming conventions.
See also
g_result_type

Definition at line 2007 of file mksqlite.cpp.

References Err::set().

◆ createResultAsMatrix()

mxArray* Mksqlite::createResultAsMatrix ( ValueSQLCols cols)
inline

Transform SQL fetch to MATLAB (cell) array.

Parameters
[in]colsSQLite fetched table
Returns
a MATLAB cell array. The array is organized as MxN matrix, where M is the row count of the table, that cols holds and N is its column count.
See also
g_result_type

Definition at line 2149 of file mksqlite.cpp.

References Err::set().

◆ createResultAsStructOfArrays()

mxArray* Mksqlite::createResultAsStructOfArrays ( ValueSQLCols cols)
inline

Transform SQL fetch to MATLAB struct of arrays.

Parameters
[in]colscontainer for SQLite fetched table
Returns
a MATLAB struct with arrays. The array size is the row count of the table, that cols holds. The struct field names are the column names, and may be modified due to MATLAB naming conventions. Pure numeric vectors are given as double arrays, other types will be returned as cell array.
See also
g_result_type

Definition at line 2067 of file mksqlite.cpp.

References Err::set().

◆ createResultColNameMatrix()

mxArray* Mksqlite::createResultColNameMatrix ( const ValueSQLCols cols)
inline

Create a MATLAB cell array of column names.

Parameters
[in]colscontainer for SQLite fetched table
Returns
a MATLAB cell array with 2 columns. First column holds the original SQLite field names and the 2nd column holds the MATLAB struct fieldnames.
See also
g_result_type

Definition at line 1963 of file mksqlite.cpp.

References Err::set(), and utils_destroy_array().

◆ ensureDbIsOpen()

bool Mksqlite::ensureDbIsOpen ( )
inline

Ensuring current database is open.

Sets m_err to MSG_DBNOTOPEN, if not.

Returns
true if database is open

Definition at line 576 of file mksqlite.cpp.

References SQLiface::isOpen(), and Err::set().

◆ returnWithError()

void Mksqlite::returnWithError ( )
inline

Terminate function.

Aborts the running function with an error message. Allocated memory (by MATLAB allocation functions) is freed automatically

Definition at line 558 of file mksqlite.cpp.

References Err::get().

Referenced by mexFunction().

+ Here is the caller graph for this function:

◆ switchDBSlot()

bool Mksqlite::switchDBSlot ( command_e  command)
inline

Selects the desired slot from SQLStack for the operation.

Parameters
commandUser operation (or query) on database
Returns
true on success

Definition at line 2595 of file mksqlite.cpp.

References Err::set().

◆ warnOnDefDbid()

bool Mksqlite::warnOnDefDbid ( )
inline

Omits a warning if database is given but superfluous.

Returns
true if dbid is undefined

Definition at line 594 of file mksqlite.cpp.

References getLocaleMsg().


The documentation for this class was generated from the following file: