Add sqlite support.
This commit is contained in:
parent
08d92a2b81
commit
2411704662
140
rework.org
140
rework.org
@ -22,74 +22,74 @@ En la siguiente tabla se encuentra la lista de estados de los SGBD que he probad
|
||||
+ *not supported* como no soportado por el SGBD.
|
||||
+ *fixed* para aquello que no existe, pero la librería lo traduce a un equivalente.
|
||||
|
||||
|------------------+---------------+---------+------------|
|
||||
|------------------+---------------+---------------+------------|
|
||||
| method | MySQL/MariaDB | sqlite3 | postgreSQL |
|
||||
|------------------+---------------+---------+------------|
|
||||
| db | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| query | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| resetQuery | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| buildQuery | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| getInstance | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| getVars | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| className | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| table | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| update | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| beginTransaction | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| rollBack | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| commit | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| add | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| save | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| delete | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| select | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| from | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| where | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| where_in | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| leftJoin | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| rightJoin | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| innerJoin | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| and | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| or | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| groupBy | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| limit | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| orderBy | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| count | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| getById | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| search | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| get | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| getFirst | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| all | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
| setNull | ok | | |
|
||||
|------------------+---------------+---------+------------|
|
||||
|------------------+---------------+---------------+------------|
|
||||
| db | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| query | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| resetQuery | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| buildQuery | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| getInstance | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| getVars | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| className | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| table | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| update | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| beginTransaction | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| rollBack | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| commit | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| add | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| save | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| delete | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| select | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| from | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| where | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| where_in | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| leftJoin | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| rightJoin | ok | not supported | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| innerJoin | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| and | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| or | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| groupBy | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| limit | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| orderBy | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| count | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| getById | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| search | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| get | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| getFirst | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| all | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
| setNull | ok | ok | |
|
||||
|------------------+---------------+---------------+------------|
|
||||
|
@ -3,8 +3,11 @@
|
||||
* Database - DuckBrain
|
||||
*
|
||||
* Clase diseñada para crear y devolver una única instancia PDO (database).
|
||||
* Depende de manera forzada de que estén definidas las constantes:
|
||||
* DB_TYPE, DB_NAME, DB_HOST, DB_USER. DB_PASS
|
||||
* Hace uso de las siguientes constantes:
|
||||
* DB_TYPE, DB_NAME, DB_HOST, DB_USER, DB_PASS
|
||||
*
|
||||
* Si DB_TYPE es sqlite, usará DB_NAME como el nombre del archivo sqlite.
|
||||
* Además DB_USER y DB_PASS, no será necesariop que estén definidos.
|
||||
*
|
||||
* @author KJ
|
||||
* @website https://kj2.me
|
||||
@ -29,7 +32,14 @@ class Database extends PDO {
|
||||
*/
|
||||
static public function getInstance() : PDO {
|
||||
if (is_null(self::$db)) {
|
||||
|
||||
if (DB_TYPE == 'sqlite') {
|
||||
$dsn = DB_TYPE .':'. DB_NAME;
|
||||
!defined('DB_USER') && define('DB_USER', '');
|
||||
!defined('DB_PASS') && define('DB_PASS', '');
|
||||
} else
|
||||
$dsn = DB_TYPE.':dbname='.DB_NAME.';host='.DB_HOST;
|
||||
|
||||
try {
|
||||
self::$db = new PDO($dsn, DB_USER, DB_PASS);
|
||||
} catch (PDOException $e) {
|
||||
@ -38,6 +48,7 @@ class Database extends PDO {
|
||||
'Error at connect to database: ' . $e->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
@ -733,9 +733,13 @@ class Model {
|
||||
static::$queryVars[':search'] = $search;
|
||||
$where = [];
|
||||
|
||||
foreach($in as $row) {
|
||||
if (DB_TYPE == 'sqlite')
|
||||
foreach($in as $row)
|
||||
$where[] = "$row LIKE '%' || :search || '%'";
|
||||
else
|
||||
foreach($in as $row)
|
||||
$where[] = "$row LIKE CONCAT('%', :search, '%')";
|
||||
}
|
||||
|
||||
|
||||
if (static::$querySelect['where']=='')
|
||||
static::$querySelect['where'] = join(' OR ', $where);
|
||||
|
Loading…
Reference in New Issue
Block a user