Skip to content

Commit c484a82

Browse files
committed
Add SQLite support
Add initial SQLite support to FacturaScripts. This change consolidates the work from the previous development branch into a single clean commit for review. Included changes: - Add SQLite compatibility changes - Adjust database-related logic where needed - Prepare the codebase for running with SQLite This commit is intended to be submitted as a clean pull request branch.
1 parent 2a42525 commit c484a82

File tree

13 files changed

+820
-8
lines changed

13 files changed

+820
-8
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
- type: postgresql
3030
version: '13'
3131
port: 5432
32+
- type: sqlite
33+
version: '3'
34+
port: 0
3235
fail-fast: false
3336

3437
name: PHP ${{ matrix.php-version }} - ${{ matrix.database.type }} ${{ matrix.database.version }}
@@ -83,7 +86,7 @@ jobs:
8386
uses: shivammathur/setup-php@v2
8487
with:
8588
php-version: ${{ matrix.php-version }}
86-
extensions: bcmath, curl, gd, iconv, mysqli, pdo_mysql, pdo_pgsql, pgsql, soap, zip, fileinfo, openssl, simplexml, mbstring, intl
89+
extensions: bcmath, curl, gd, iconv, mysqli, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, soap, zip, fileinfo, openssl, simplexml, mbstring, intl
8790
coverage: xdebug
8891
tools: composer:v2
8992
env:
@@ -109,10 +112,13 @@ jobs:
109112
echo "Testing ${{ matrix.database.type }} ${{ matrix.database.version }} connection..."
110113
mysql --host=${{ env.DB_HOST }} --user=${{ env.DB_USER }} --password=${{ env.DB_PASS }} -e "SHOW DATABASES;"
111114
mysql --host=${{ env.DB_HOST }} --user=${{ env.DB_USER }} --password=${{ env.DB_PASS }} -e "SELECT VERSION();"
112-
else
115+
elif [ "${{ matrix.database.type }}" = "postgresql" ]; then
113116
echo "Testing PostgreSQL ${{ matrix.database.version }} connection..."
114117
PGPASSWORD=${{ env.DB_PASS }} psql -h ${{ env.DB_HOST }} -U ${{ env.DB_USER }} -d ${{ env.DB_NAME }} -c "\l"
115118
PGPASSWORD=${{ env.DB_PASS }} psql -h ${{ env.DB_HOST }} -U ${{ env.DB_USER }} -d ${{ env.DB_NAME }} -c "SELECT version();"
119+
else
120+
echo "Testing SQLite ${{ matrix.database.version }} support..."
121+
php -r 'exit(in_array("sqlite", PDO::getAvailableDrivers(), true) ? 0 : 1);'
116122
fi
117123
118124
- name: Create application config
@@ -139,7 +145,7 @@ jobs:
139145
define('FS_DISABLE_ADD_PLUGINS', false);
140146
define('FS_DISABLE_RM_PLUGINS', false);
141147
EOF
142-
else
148+
elif [ "${{ matrix.database.type }}" = "postgresql" ]; then
143149
cat > config.php << 'EOF'
144150
<?php
145151
define('FS_COOKIES_EXPIRE', 31536000);
@@ -159,6 +165,26 @@ jobs:
159165
define('FS_DISABLE_ADD_PLUGINS', false);
160166
define('FS_DISABLE_RM_PLUGINS', false);
161167
EOF
168+
else
169+
cat > config.php << 'EOF'
170+
<?php
171+
define('FS_COOKIES_EXPIRE', 31536000);
172+
define('FS_ROUTE', '');
173+
define('FS_DB_TYPE', 'sqlite');
174+
define('FS_DB_HOST', '');
175+
define('FS_DB_PORT', 0);
176+
define('FS_DB_NAME', 'MyFiles/facturascripts_test.sqlite');
177+
define('FS_DB_USER', '');
178+
define('FS_DB_PASS', '');
179+
define('FS_DB_FOREIGN_KEYS', true);
180+
define('FS_DB_TYPE_CHECK', true);
181+
define('FS_LANG', 'es_ES');
182+
define('FS_TIMEZONE', 'Europe/Madrid');
183+
define('FS_HIDDEN_PLUGINS', '');
184+
define('FS_DEBUG', true);
185+
define('FS_DISABLE_ADD_PLUGINS', false);
186+
define('FS_DISABLE_RM_PLUGINS', false);
187+
EOF
162188
fi
163189
164190
- name: Run PHPUnit tests

Core/Base/DataBase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
use FacturaScripts\Core\Base\DataBase\DataBaseEngine;
2323
use FacturaScripts\Core\Base\DataBase\MysqlEngine;
2424
use FacturaScripts\Core\Base\DataBase\PostgresqlEngine;
25+
use FacturaScripts\Core\Base\DataBase\SqliteEngine;
2526
use FacturaScripts\Core\KernelException;
2627
use FacturaScripts\Core\Tools;
2728

2829
/**
29-
* Generic class of access to the database, either MySQL or PostgreSQL.
30+
* Generic class of access to the database, either MySQL, PostgreSQL or SQLite.
3031
*
3132
* @author Carlos García Gómez <carlos@facturascripts.com>
3233
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
@@ -84,6 +85,10 @@ public function __construct()
8485
self::$engine = new PostgresqlEngine();
8586
break;
8687

88+
case 'sqlite':
89+
self::$engine = new SqliteEngine();
90+
break;
91+
8792
default:
8893
self::$engine = new MysqlEngine();
8994
break;

0 commit comments

Comments
 (0)