dolibarr 25.0.0-alpha
DoliDBSqlite3 Class Reference

Class to manage Dolibarr database access for a SQLite database. More...

Inheritance diagram for DoliDBSqlite3:
Collaboration diagram for DoliDBSqlite3:

Public Member Functions

 __construct ($type, $host, $user, $pass, $name='', $port=0, $forcenew=false)
 Constructor.
 
 convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax.
 
 select_db ($database)
 Select a database.
 
 connect ($host, $login, $passwd, $name, $port=0, $forcenew=false)
 Connection to server.
 
 getVersion ()
 Return version of database server.
 
 getDriverInfo ()
 Return version of database client driver.
 
 close ()
 Close database connection.
 
 query ($query, $usesavepoint=0, $type='auto', $result_mode=0)
 Execute a SQL request and return the resultset.
 
 fetch_object ($resultset)
 Returns the current line (as an object) for the resultset cursor.
 
 fetch_array ($resultset)
 Return datas as an array.
 
 fetch_row ($resultset)
 Return datas as an array.
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT.
 
 affected_rows ($resultset)
 Return number of lines for result of a SELECT.
 
 free ($resultset=null)
 Free last resultset used.
 
 escape ($stringtoencode)
 Escape a string to insert data.
 
 escapeforlike ($stringtoencode)
 Escape a string to insert data into a like.
 
 errno ()
 Renvoie le code erreur generique de l'operation precedente.
 
 error ()
 Renvoie le texte de l'erreur mysql de l'operation precedente.
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT.
 
 encrypt ($fieldorvalue, $withQuotes=1)
 Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.
 
 decrypt ($value)
 Decrypt sensitive data in database.
 
 DDLGetConnectId ()
 Return connection ID.
 
 DDLCreateDb ($database, $charset='', $collation='', $owner='')
 Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We force to create database with charset this->forcecharset and collate this->forcecollate.
 
 DDLListTables ($database, $table='')
 List tables into a database.
 
 DDLListTablesFull ($database, $table='')
 List tables into a database with table type.
 
 DDLInfoTable ($table)
 List information of columns into a table.
 
 DDLCreateTable ($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
 Create a table into database.
 
 DDLDropTable ($table)
 Drop a table into database.
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field.
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table.
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table.
 
 DDLDropField ($table, $field_name)
 Drop a field from table.
 
 DDLCreateUser ($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
 Create a user and privileges to connect to database (even if database does not exists yet)
 
 getDefaultCharacterSetDatabase ()
 Return charset used to store data in database.
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database.
 
 getDefaultCollationDatabase ()
 Return collation used in database.
 
 getListOfCollation ()
 Return list of available collations that can be used for database.
 
 getPathOfDump ()
 Return full path of dump program.
 
 getPathOfRestore ()
 Return full path of restore program.
 
 getServerParametersValues ($filter='')
 Return value of server parameters.
 
 getServerStatusValues ($filter='')
 Return value of server status.
 
 prepare ($sql)
 Prepare a SQL statement for execution.
 
 execute ($stmt, $params=array())
 Execute a statement previously created with prepare().
 
- Public Member Functions inherited from DoliDB
 prefix ()
 Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=...).
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF.
 
 stddevpop ($nameoffield)
 Return SQL string to aggregate using the Standard Deviation of population.
 
 hintindex ($nameofindex, $mode=1)
 Return SQL string to force an index.
 
 regexpsql ($subject, $pattern, $sqlstring=0)
 Format a SQL REGEXP.
 
 idate ($param, $gm='tzserver')
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
 
 lasterrno ()
 Return last error code.
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0, $allowsspace=0, $allowschars=1)
 Sanitize a string for SQL forging.
 
 begin ($textinlog='')
 Start transaction.
 
 commit ($log='')
 Validate a database transaction.
 
 rollback ($log='')
 Cancel a transaction and go back to initial data values.
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request.
 
 getVersionArray ()
 Return version of database server into an array.
 
 lastquery ()
 Return last request executed with query()
 
 order ($sortfield='', $sortorder='')
 Define sort criteria of request.
 
 lasterror ()
 Return last error label.
 
 jdate ($string, $gm='tzserver')
 Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -> 3600 with server TZ = +1 and $gm='tzserver' 19700101020000 -> 7200 whatever is server TZ if $gm='gmt'.
 
 lastqueryerror ()
 Return last query in error.
 
 getRow ($sql)
 Return first result from query as object Note : This method executes a given SQL query and retrieves the first row of results as an object.
 
 getRows ($sql)
 Return all results from query as an array of objects.
 
 getNextAutoIncrementId ($table)
 Get the last ID of an auto-increment field of a table.
 
- Public Member Functions inherited from Database
 sanitize ($stringtosanitize)
 Sanitize a string for SQL forging.
 

Public Attributes

 $type = 'sqlite3'
 Database type.
 
const LABEL = 'Sqlite3'
 Database label.
 
const VERSIONMIN = '3.0.0'
 Version min database.
 
- Public Attributes inherited from DoliDB
const VERSIONMIN = self::VERSIONMIN
 Force subclass to implement VERSIONMIN - required DB version.
 
const LABEL = self::LABEL
 Force subclass to implement LABEL - description of DB type.
 

Private Member Functions

 addCustomFunction ($name, $arg_count=-1)
 Add a custom function in the database engine (STORED PROCEDURE) Notes:
 

Detailed Description

Class to manage Dolibarr database access for a SQLite database.

Definition at line 35 of file sqlite3.class.php.

Constructor & Destructor Documentation

◆ __construct()

DoliDBSqlite3::__construct ( $type,
$host,
$user,
$pass,
$name = '',
$port = 0,
$forcenew = false )

Constructor.

This create an opened connection to a database server and eventually to a database

Parameters
string$typeType of database (mysql, pgsql...). Not used.
string$hostAddress of database server
string$userName of the authorized user
string$passPassword
string$nameNom de la database
int$portPort of database server
bool$forcenewNot used by this driver: sqlite3 always opens a genuinely new connection. Kept for signature parity with the Database interface.

Definition at line 71 of file sqlite3.class.php.

References $conf, addCustomFunction(), connect(), dol_syslog(), and error().

Member Function Documentation

◆ addCustomFunction()

DoliDBSqlite3::addCustomFunction ( $name,
$arg_count = -1 )
private

Add a custom function in the database engine (STORED PROCEDURE) Notes:

  • The custom function is prefixed with 'db'
  • The function must be static and public.
  • The number of arguments is automatically determined when arg_count is < 0
Parameters
string$nameFunction name to define in Sqlite
int$arg_countArguments count
Returns
void

Definition at line 1425 of file sqlite3.class.php.

Referenced by __construct().

◆ affected_rows()

DoliDBSqlite3::affected_rows ( $resultset)

Return number of lines for result of a SELECT.

Parameters
SQLite3Result$resultsetResulset of requests
Returns
int Nb of lines
See also
affected_rows()

Implements Database.

Definition at line 613 of file sqlite3.class.php.

References num_rows().

◆ close()

DoliDBSqlite3::close ( )

Close database connection.

Returns
bool True if disconnect successful, false otherwise
See also
connect()

Implements Database.

Definition at line 385 of file sqlite3.class.php.

References dol_syslog().

◆ connect()

DoliDBSqlite3::connect ( $host,
$login,
$passwd,
$name,
$port = 0,
$forcenew = false )

Connection to server.

Parameters
string$hostdatabase server host
string$loginlogin
string$passwdpassword
string$namename of database (not used for mysql, used for pgsql)
integer$portPort of database server
bool$forcenewNot used by this driver: sqlite3 always opens a genuinely new connection. Kept for signature parity with the Database interface.
Returns
SQLite3|false Database access handler
See also
close()

Implements Database.

Definition at line 329 of file sqlite3.class.php.

References dol_syslog(), and error().

Referenced by __construct().

◆ convertSQLFromMysql()

DoliDBSqlite3::convertSQLFromMysql ( $line,
$type = 'ddl' )

Convert a SQL request in Mysql syntax to native syntax.

Parameters
string$lineSQL request line to convert
string$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
Returns
string SQL request line converted

Implements Database.

Definition at line 147 of file sqlite3.class.php.

References $type, and dol_syslog().

Referenced by query().

◆ DDLAddField()

DoliDBSqlite3::DDLAddField ( $table,
$field_name,
$field_desc,
$field_position = "" )

Create a new field into table.

Parameters
string$tableTable name
string$field_nameField name to add
array{type:string,label?:string,enabled?:int<0,2>|string,position?:int,notnull?:int,visible?:int,noteditable?:int,default?:string,extra?:string,null?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}$field_desc Associative array of description of the field to insert [parameter name][parameter value]
string$field_positionOptional e.g.: "after some_field"
Returns
int Return integer <0 if KO, >0 if OK

Implements Database.

Definition at line 1112 of file sqlite3.class.php.

◆ DDLCreateDb()

DoliDBSqlite3::DDLCreateDb ( $database,
$charset = '',
$collation = '',
$owner = '' )

Create a new database Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated We force to create database with charset this->forcecharset and collate this->forcecollate.

Parameters
string$databaseDatabase name to create
string$charsetCharset used to store data
string$collationCharset used to sort data
string$ownerUsername of database owner
Returns
false|SQLite3Result Resource defined if OK, null if KO

Implements Database.

Definition at line 853 of file sqlite3.class.php.

◆ DDLCreateTable()

DoliDBSqlite3::DDLCreateTable ( $table,
$fields,
$primary_key,
$type,
$unique_keys = null,
$fulltext_keys = null,
$keys = null )

Create a table into database.

Parameters
string$tableNom de la table
array<string,array{type:string,label?:string,enabled?:int<0,2>|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array<int|string,string>,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>,value?:string,attribute?:string,null?:string,extra?:string}>$fields Tableau associatif [nom champ][tableau des descriptions]
string$primary_keyNom du champ qui sera la clef primaire
string$typeType de la table
?array<string,mixed>$unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur
string[]$fulltext_keysTableau des Nom de champs qui seront indexes en fulltext
array<string,mixed>$keys Tableau des champs cles noms => valeur
Returns
int Return integer <0 if KO, >=0 if OK

Implements Database.

Definition at line 978 of file sqlite3.class.php.

◆ DDLCreateUser()

DoliDBSqlite3::DDLCreateUser ( $dolibarr_main_db_host,
$dolibarr_main_db_user,
$dolibarr_main_db_pass,
$dolibarr_main_db_name )

Create a user and privileges to connect to database (even if database does not exists yet)

Parameters
string$dolibarr_main_db_hostIp serveur
string$dolibarr_main_db_userNom user a creer
string$dolibarr_main_db_passPassword user a creer
string$dolibarr_main_db_nameDatabase name where user must be granted
Returns
int Return integer <0 if KO, >=0 if OK

Implements Database.

Definition at line 1223 of file sqlite3.class.php.

◆ DDLDescTable()

DoliDBSqlite3::DDLDescTable ( $table,
$field = "" )

Return a pointer of line with description of a table or field.

Parameters
string$tableName of table
string$fieldOptionnel : Name of field if we want description of field
Returns
bool|SQLite3Result Resource

Implements Database.

Definition at line 1092 of file sqlite3.class.php.

◆ DDLDropField()

DoliDBSqlite3::DDLDropField ( $table,
$field_name )

Drop a field from table.

Parameters
string$tableName of table
string$field_nameName of field to drop
Returns
int Return integer <0 if KO, >0 if OK

Implements Database.

Definition at line 1199 of file sqlite3.class.php.

◆ DDLDropTable()

DoliDBSqlite3::DDLDropTable ( $table)

Drop a table into database.

Parameters
string$tableName of table
Returns
int Return integer <0 if KO, >=0 if OK

Implements Database.

Definition at line 1070 of file sqlite3.class.php.

◆ DDLGetConnectId()

DoliDBSqlite3::DDLGetConnectId ( )

Return connection ID.

Returns
string Id connection

Implements Database.

Definition at line 834 of file sqlite3.class.php.

◆ DDLInfoTable()

DoliDBSqlite3::DDLInfoTable ( $table)

List information of columns into a table.

Parameters
string$tableName of table
Returns
array<array<mixed>> Table with information of columns in the table

TODO modify for sqlite

Implements Database.

Definition at line 946 of file sqlite3.class.php.

◆ DDLListTables()

DoliDBSqlite3::DDLListTables ( $database,
$table = '' )

List tables into a database.

Parameters
string$databaseName of database
string$tableName of table filter ('xxx')
Returns
string[] List of tables in an array

Implements Database.

Definition at line 881 of file sqlite3.class.php.

◆ DDLListTablesFull()

DoliDBSqlite3::DDLListTablesFull ( $database,
$table = '' )

List tables into a database with table type.

Parameters
string$databaseName of database
string$tableName of table filter ('xxx')
Returns
array<array{0:string,1:string}> List of tables in an array

Implements Database.

Definition at line 913 of file sqlite3.class.php.

◆ DDLUpdateField()

DoliDBSqlite3::DDLUpdateField ( $table,
$field_name,
$field_desc )

Update format of a field into a table.

Parameters
string$tableName of table
string$field_nameName of field to modify
array{type:string,label?:string,enabled?:int<0,2>|string,position?:int,notnull?:int,visible?:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string,value?:string,null?:string}$field_desc Array with description of field format
Returns
int Return integer <0 if KO, >0 if OK

Implements Database.

Definition at line 1168 of file sqlite3.class.php.

◆ decrypt()

DoliDBSqlite3::decrypt ( $value)

Decrypt sensitive data in database.

Parameters
string$valueValue to decrypt
Returns
string Decrypted value if used

Implements Database.

Definition at line 804 of file sqlite3.class.php.

References $conf.

◆ encrypt()

DoliDBSqlite3::encrypt ( $fieldorvalue,
$withQuotes = 1 )

Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings.

Parameters
string$fieldorvalueField name or value to encrypt
int<1,1>$withQuotes Return string including the SQL simple quotes. This param must always be 1 (Value 0 is bugged and deprecated).
Returns
string XXX(field) or XXX('value') or field or 'value'

Implements Database.

Definition at line 775 of file sqlite3.class.php.

References $conf, and escape().

◆ errno()

DoliDBSqlite3::errno ( )

Renvoie le code erreur generique de l'operation precedente.

Returns
string Error code (Examples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)

Implements Database.

Definition at line 674 of file sqlite3.class.php.

References error().

Referenced by query().

◆ error()

DoliDBSqlite3::error ( )

Renvoie le texte de l'erreur mysql de l'operation precedente.

Returns
string Error text

Implements Database.

Definition at line 743 of file sqlite3.class.php.

Referenced by __construct(), connect(), errno(), and query().

◆ escape()

DoliDBSqlite3::escape ( $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 653 of file sqlite3.class.php.

Referenced by encrypt(), and query().

◆ escapeforlike()

DoliDBSqlite3::escapeforlike ( $stringtoencode)

Escape a string to insert data into a like.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

Definition at line 664 of file sqlite3.class.php.

◆ execute()

DoliDBSqlite3::execute ( $stmt,
$params = array() )

Execute a statement previously created with prepare().

Parameters
SQLite3Stmt$stmtStatement returned by prepare()
array<int,mixed>$params Ordered list of values for the '?' placeholders
Returns
SQLite3Result|bool A SQLite3Result (usable with fetch_object()/num_rows()/free()) for a SELECT, true for another successful statement, false on error
See also
prepare()

Reimplemented from DoliDB.

Definition at line 1480 of file sqlite3.class.php.

◆ fetch_array()

DoliDBSqlite3::fetch_array ( $resultset)

Return datas as an array.

Parameters
SQLite3Result$resultsetResultset of request
Returns
array<int|string,mixed>|null|false Array or null if KO or end of cursor

Implements Database.

Definition at line 547 of file sqlite3.class.php.

◆ fetch_object()

DoliDBSqlite3::fetch_object ( $resultset)

Returns the current line (as an object) for the resultset cursor.

Parameters
SQLite3Result$resultsetCursor of the desired query
Returns
false|object Object result line or false if KO or end of cursor

Implements Database.

Definition at line 524 of file sqlite3.class.php.

◆ fetch_row()

DoliDBSqlite3::fetch_row ( $resultset)

Return datas as an array.

Parameters
SQLite3Result$resultsetResultset of request
Returns
array<int,mixed>|null|int<0,0> Array or null if KO or end of cursor or 0 if resultset is bool

Implements Database.

Definition at line 566 of file sqlite3.class.php.

◆ free()

DoliDBSqlite3::free ( $resultset = null)

Free last resultset used.

Parameters
SQLite3Result | null$resultsetResult set of request
Returns
void

Implements Database.

Definition at line 635 of file sqlite3.class.php.

◆ getDefaultCharacterSetDatabase()

DoliDBSqlite3::getDefaultCharacterSetDatabase ( )

Return charset used to store data in database.

Returns
string Charset

Implements Database.

Definition at line 1263 of file sqlite3.class.php.

◆ getDefaultCollationDatabase()

DoliDBSqlite3::getDefaultCollationDatabase ( )

Return collation used in database.

Returns
string Collation value

Implements Database.

Definition at line 1287 of file sqlite3.class.php.

◆ getDriverInfo()

DoliDBSqlite3::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implements Database.

Definition at line 373 of file sqlite3.class.php.

◆ getListOfCharacterSet()

DoliDBSqlite3::getListOfCharacterSet ( )

Return list of available charset that can be used to store data in database.

Returns
?array<int,array{charset:string,description:string}> List of Charset

Implements Database.

Definition at line 1273 of file sqlite3.class.php.

◆ getListOfCollation()

DoliDBSqlite3::getListOfCollation ( )

Return list of available collations that can be used for database.

Returns
?array<int,array{collation:string}> List of Collation

Implements Database.

Definition at line 1297 of file sqlite3.class.php.

◆ getPathOfDump()

DoliDBSqlite3::getPathOfDump ( )

Return full path of dump program.

Returns
string Full path of dump program

Implements Database.

Definition at line 1310 of file sqlite3.class.php.

◆ getPathOfRestore()

DoliDBSqlite3::getPathOfRestore ( )

Return full path of restore program.

Returns
string Full path of restore program

Implements Database.

Definition at line 1329 of file sqlite3.class.php.

◆ getServerParametersValues()

DoliDBSqlite3::getServerParametersValues ( $filter = '')

Return value of server parameters.

Parameters
string$filterFilter list on a particular value
Returns
array<string,string> Array of key-values (key=>value)

Implements Database.

Definition at line 1349 of file sqlite3.class.php.

◆ getServerStatusValues()

DoliDBSqlite3::getServerStatusValues ( $filter = '')

Return value of server status.

Parameters
string$filterFilter list on a particular value
Returns
array<string,string> Array of key-values (key=>value)

Implements Database.

Definition at line 1396 of file sqlite3.class.php.

◆ getVersion()

DoliDBSqlite3::getVersion ( )

Return version of database server.

Returns
string Version string

Implements Database.

Definition at line 362 of file sqlite3.class.php.

◆ last_insert_id()

DoliDBSqlite3::last_insert_id ( $tab,
$fieldid = 'rowid' )

Get last ID after an insert INSERT.

Parameters
string$tabTable name concerned by insert. Not used for mysql, but required for Postgresql
string$fieldidField name
Returns
int Id of row

Implements Database.

Definition at line 761 of file sqlite3.class.php.

◆ num_rows()

DoliDBSqlite3::num_rows ( $resultset)

Return number of lines for result of a SELECT.

Parameters
SQLite3Result$resultsetResulset of requests
Returns
int Nb of lines
See also
affected_rows()

Implements Database.

Definition at line 589 of file sqlite3.class.php.

Referenced by affected_rows().

◆ prepare()

DoliDBSqlite3::prepare ( $sql)

Prepare a SQL statement for execution.

Use '?' as the placeholder for every bound value.

Parameters
string$sqlSQL query with '?' placeholders
Returns
SQLite3Stmt|false
See also
execute()

Reimplemented from DoliDB.

Definition at line 1448 of file sqlite3.class.php.

◆ query()

DoliDBSqlite3::query ( $query,
$usesavepoint = 0,
$type = 'auto',
$result_mode = 0 )

Execute a SQL request and return the resultset.

Parameters
string$querySQL query string
int$usesavepoint0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
string$typeType of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
int$result_modeResult mode (not used with sqlite)
Returns
false|SQLite3Result Resultset of answer

Implements Database.

Definition at line 409 of file sqlite3.class.php.

References $conf, $type, convertSQLFromMysql(), dol_syslog(), errno(), error(), escape(), getDolGlobalString(), DoliDB\lasterrno(), DoliDB\lasterror(), DoliDB\lastquery(), DoliDB\lastqueryerror(), and query().

Referenced by query().

◆ select_db()

DoliDBSqlite3::select_db ( $database)

Select a database.

Parameters
string$databaseName of database
Returns
boolean true if OK, false if KO

Implements Database.

Definition at line 307 of file sqlite3.class.php.

References dol_syslog().


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