dolibarr  18.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
DoliDBSqlite3 Class Reference

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

Inheritance diagram for DoliDBSqlite3:
Inheritance graph
[legend]
Collaboration diagram for DoliDBSqlite3:
Collaboration graph
[legend]

Public Member Functions

 __construct ($type, $host, $user, $pass, $name='', $port=0)
 Constructor. More...
 
 select_db ($database)
 Select a database. More...
 
 connect ($host, $login, $passwd, $name, $port=0)
 Connexion to server. More...
 
 getVersion ()
 Return version of database server. More...
 
 getDriverInfo ()
 Return version of database client driver. More...
 
 close ()
 Close database connexion. More...
 
 query ($query, $usesavepoint=0, $type='auto', $result_mode=0)
 Execute a SQL request and return the resultset. More...
 
 fetch_object ($resultset)
 Returns the current line (as an object) for the resultset cursor. More...
 
 fetch_array ($resultset)
 Return datas as an array. More...
 
 fetch_row ($resultset)
 Return datas as an array. More...
 
 num_rows ($resultset)
 Return number of lines for result of a SELECT. More...
 
 affected_rows ($resultset)
 Return number of lines for result of a SELECT. More...
 
 free ($resultset=null)
 Free last resultset used. More...
 
 escape ($stringtoencode)
 Escape a string to insert data. More...
 
 escapeforlike ($stringtoencode)
 Escape a string to insert data into a like. More...
 
 errno ()
 Renvoie le code erreur generique de l'operation precedente. More...
 
 error ()
 Renvoie le texte de l'erreur mysql de l'operation precedente. More...
 
 last_insert_id ($tab, $fieldid='rowid')
 Get last ID after an insert INSERT. More...
 
 encrypt ($fieldorvalue, $withQuotes=1)
 Encrypt sensitive data in database Warning: This function includes the escape and add the SQL simple quotes on strings. More...
 
 decrypt ($value)
 Decrypt sensitive data in database. More...
 
 DDLGetConnectId ()
 Return connexion ID. More...
 
 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. More...
 
 DDLListTables ($database, $table='')
 List tables into a database. More...
 
 DDLListTablesFull ($database, $table='')
 List tables into a database with table type. More...
 
 DDLInfoTable ($table)
 List information of columns into a table. More...
 
 DDLCreateTable ($table, $fields, $primary_key, $type, $unique_keys=null, $fulltext_keys=null, $keys=null)
 Create a table into database. More...
 
 DDLDropTable ($table)
 Drop a table into database. More...
 
 DDLDescTable ($table, $field="")
 Return a pointer of line with description of a table or field. More...
 
 DDLAddField ($table, $field_name, $field_desc, $field_position="")
 Create a new field into table. More...
 
 DDLUpdateField ($table, $field_name, $field_desc)
 Update format of a field into a table. More...
 
 DDLDropField ($table, $field_name)
 Drop a field from table. More...
 
 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) More...
 
 getDefaultCharacterSetDatabase ()
 Return charset used to store data in database. More...
 
 getListOfCharacterSet ()
 Return list of available charset that can be used to store data in database. More...
 
 getDefaultCollationDatabase ()
 Return collation used in database. More...
 
 getListOfCollation ()
 Return list of available collation that can be used for database. More...
 
 getPathOfDump ()
 Return full path of dump program. More...
 
 getPathOfRestore ()
 Return full path of restore program. More...
 
 getServerParametersValues ($filter='')
 Return value of server parameters. More...
 
 getServerStatusValues ($filter='')
 Return value of server status. More...
 
- 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=...). More...
 
 ifsql ($test, $resok, $resko)
 Format a SQL IF. More...
 
 hintindex ($nameofindex)
 Return SQL string to force an index. More...
 
 regexpsql ($subject, $pattern, $sqlstring=false)
 Format a SQL REGEXP. More...
 
 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. More...
 
 lasterrno ()
 Return last error code. More...
 
 sanitize ($stringtosanitize, $allowsimplequote=0, $allowsequals=0)
 Sanitize a string for SQL forging. More...
 
 begin ($textinlog='')
 Start transaction. More...
 
 commit ($log='')
 Validate a database transaction. More...
 
 rollback ($log='')
 Cancel a transaction and go back to initial data values. More...
 
 plimit ($limit=0, $offset=0)
 Define limits and offset of request. More...
 
 getVersionArray ()
 Return version of database server into an array. More...
 
 lastquery ()
 Return last request executed with query() More...
 
 order ($sortfield='', $sortorder='')
 Define sort criteria of request. More...
 
 lasterror ()
 Return last error label. More...
 
 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 whaterver is server TZ if $gm='gmt'. More...
 
 lastqueryerror ()
 Return last query in error. More...
 
 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. More...
 
 getRows ($sql)
 Return all results from query as an array of objects Note : This method executes a given SQL query and retrieves all row of results as an array of objects. More...
 
- Public Member Functions inherited from Database
 idate ($param)
 Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. More...
 
 sanitize ($stringtosanitize)
 Sanitize a string for SQL forging. More...
 

Static Public Member Functions

static convertSQLFromMysql ($line, $type='ddl')
 Convert a SQL request in Mysql syntax to native syntax. More...
 

Public Attributes

 $type = 'sqlite3'
 Database type.
 
const LABEL = 'Sqlite3'
 Database label.
 
const VERSIONMIN = '3.0.0'
 Version min database.
 

Private Member Functions

 addCustomFunction ($name, $arg_count=-1)
 Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees. More...
 

Static Private Member Functions

static calc_daynr ($year, $month, $day)
 calc_daynr More...
 
static calc_weekday ($daynr, $sunday_first_day_of_week)
 calc_weekday More...
 
static calc_days_in_year ($year)
 calc_days_in_year More...
 
static calc_week ($year, $month, $day, $week_behaviour, &$calc_year)
 calc_week More...
 

Detailed Description

Class to manage Dolibarr database access for a SQLite database.

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

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

Parameters
string$typeType of database (mysql, pgsql...)
string$hostAddress of database server
string$userNom de l'utilisateur autorise
string$passMot de passe
string$nameNom de la database
int$portPort of database server

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

Member Function Documentation

◆ addCustomFunction()

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

Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees.

Note: le nom de la fonction personnalisee est prefixee par 'db'. La fonction doit ĂȘtre statique et publique. Le nombre de parametres est determine automatiquement.

Parameters
string$nameLe nom de la fonction a definir dans Sqlite
int$arg_countArg count
Returns
void

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

◆ 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 605 of file sqlite3.class.php.

References num_rows().

◆ calc_daynr()

static DoliDBSqlite3::calc_daynr (   $year,
  $month,
  $day 
)
staticprivate

calc_daynr

Parameters
int$yearYear
int$monthMonth
int$dayDay
Returns
int Formatted date

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

◆ calc_days_in_year()

static DoliDBSqlite3::calc_days_in_year (   $year)
staticprivate

calc_days_in_year

Parameters
string$yearYear
Returns
int Nb of days in year

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

◆ calc_week()

static DoliDBSqlite3::calc_week (   $year,
  $month,
  $day,
  $week_behaviour,
$calc_year 
)
staticprivate

calc_week

Parameters
string$yearYear
string$monthMonth
string$dayDay
string$week_behaviourWeek behaviour
string$calc_year???
Returns
string ???

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

◆ calc_weekday()

static DoliDBSqlite3::calc_weekday (   $daynr,
  $sunday_first_day_of_week 
)
staticprivate

calc_weekday

Parameters
int$daynr???
bool$sunday_first_day_of_week???
Returns
int

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

◆ close()

DoliDBSqlite3::close ( )

Close database connexion.

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

Implements Database.

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

References dol_syslog().

◆ connect()

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

Connexion 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
Returns
SQLite3|string Database access handler
See also
close()

Implements Database.

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

◆ convertSQLFromMysql()

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

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 141 of file sqlite3.class.php.

◆ DDLAddField()

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

Create a new field into table.

Parameters
string$tableName of table
string$field_nameName of field to add
string$field_descTableau associatif de description du champ a inserer[nom du parametre][valeur du parametre]
string$field_positionOptionnel ex.: "after champtruc"
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 1086 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
SQLite3Result resource defined if OK, null if KO

Implements Database.

Definition at line 847 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$fieldsTableau associatif [nom champ][tableau des descriptions]
string$primary_keyNom du champ qui sera la clef primaire
string$typeType de la table
array$unique_keysTableau associatifs Nom de champs qui seront clef unique => valeur
array$fulltext_keysTableau des Nom de champs qui seront indexes en fulltext
array$keysTableau des champs cles noms => valeur
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 971 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_passMot de passe user a creer
string$dolibarr_main_db_nameDatabase name where user must be granted
Returns
int <0 if KO, >=0 if OK

Implements Database.

Definition at line 1180 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 1066 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 <0 if KO, >0 if OK

Implements Database.

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

◆ DDLDropTable()

DoliDBSqlite3::DDLDropTable (   $table)

Drop a table into database.

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

Implements Database.

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

◆ DDLGetConnectId()

DoliDBSqlite3::DDLGetConnectId ( )

Return connexion ID.

Returns
string Id connexion

Implements Database.

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

◆ DDLInfoTable()

DoliDBSqlite3::DDLInfoTable (   $table)

List information of columns into a table.

Parameters
string$tableName of table
Returns
array Tableau des informations des champs de la table TODO modify for sqlite

Implements Database.

Definition at line 939 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
array List of tables in an array

Implements Database.

Definition at line 875 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 List of tables in an array

Implements Database.

Definition at line 907 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
string$field_descArray with description of field format
Returns
int <0 if KO, >0 if OK

Implements Database.

Definition at line 1132 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 798 of file sqlite3.class.php.

◆ 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$withQuotesReturn 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 769 of file sqlite3.class.php.

◆ errno()

DoliDBSqlite3::errno ( )

Renvoie le code erreur generique de l'operation precedente.

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

Implements Database.

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

References error().

◆ error()

DoliDBSqlite3::error ( )

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

Returns
string Error text

Implements Database.

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

Referenced by errno().

◆ escape()

DoliDBSqlite3::escape (   $stringtoencode)

Escape a string to insert data.

Parameters
string$stringtoencodeString to escape
Returns
string String escaped

Implements Database.

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

◆ 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 658 of file sqlite3.class.php.

◆ fetch_array()

DoliDBSqlite3::fetch_array (   $resultset)

Return datas as an array.

Parameters
SQLite3Result$resultsetResultset of request
Returns
false|array Array or false if KO or end of cursor

Implements Database.

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

◆ fetch_object()

DoliDBSqlite3::fetch_object (   $resultset)

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

Parameters
SQLite3Result$resultsetCurseur de la requete voulue
Returns
false|object Object result line or false if KO or end of cursor

Implements Database.

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

◆ fetch_row()

DoliDBSqlite3::fetch_row (   $resultset)

Return datas as an array.

Parameters
SQLite3Result$resultsetResultset of request
Returns
false|array Array or false if KO or end of cursor

Implements Database.

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

◆ free()

DoliDBSqlite3::free (   $resultset = null)

Free last resultset used.

Parameters
SQLite3Result$resultsetCurseur de la requete voulue
Returns
void

Implements Database.

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

◆ getDefaultCharacterSetDatabase()

DoliDBSqlite3::getDefaultCharacterSetDatabase ( )

Return charset used to store data in database.

Returns
string Charset

Implements Database.

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

◆ getDefaultCollationDatabase()

DoliDBSqlite3::getDefaultCollationDatabase ( )

Return collation used in database.

Returns
string Collation value

Implements Database.

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

◆ getDriverInfo()

DoliDBSqlite3::getDriverInfo ( )

Return version of database client driver.

Returns
string Version string

Implements Database.

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

◆ getListOfCharacterSet()

DoliDBSqlite3::getListOfCharacterSet ( )

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

Returns
array List of Charset

Implements Database.

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

◆ getListOfCollation()

DoliDBSqlite3::getListOfCollation ( )

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

Returns
array List of Collation

Implements Database.

Definition at line 1254 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 1268 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 1287 of file sqlite3.class.php.

◆ getServerParametersValues()

DoliDBSqlite3::getServerParametersValues (   $filter = '')

Return value of server parameters.

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

Implements Database.

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

◆ getServerStatusValues()

DoliDBSqlite3::getServerStatusValues (   $filter = '')

Return value of server status.

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

Implements Database.

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

◆ getVersion()

DoliDBSqlite3::getVersion ( )

Return version of database server.

Returns
string Version string

Implements Database.

Definition at line 355 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. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
string$fieldidField name
Returns
int Id of row

Implements Database.

Definition at line 755 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 582 of file sqlite3.class.php.

Referenced by affected_rows().

◆ query()

SQLite3Result boolean Resultset of last 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
bool|SQLite3Result Resultset of answer

Implements Database.

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

◆ 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 301 of file sqlite3.class.php.

References dol_syslog().


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