| 1 |
SQLite2 support in freepbx |
|---|
| 2 |
-------------------------- |
|---|
| 3 |
|
|---|
| 4 |
If you are reading this, you should be aware that the support for sqlite2 is not |
|---|
| 5 |
perfect at the writing of this document. Many things are garanteed not to work, and |
|---|
| 6 |
patches are more then welcome. |
|---|
| 7 |
|
|---|
| 8 |
This document speaks about SQLite2 on Debian Sarge/Rapid 1.1.1, and not other versions. |
|---|
| 9 |
SQLite3 is not supported, since there are no php4 bindings for it on Debian. The code should |
|---|
| 10 |
work on other operating systems or distributions, but it shuold work on others. Any feedback is |
|---|
| 11 |
welcomed. |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
1) Creating the initial tables |
|---|
| 15 |
------------------------------ |
|---|
| 16 |
The first step will be creating a default "database" for freepbx to use. We cannot use the |
|---|
| 17 |
standard newinstall.sql file, because of these reasons: |
|---|
| 18 |
|
|---|
| 19 |
a) Usage of backtips ` |
|---|
| 20 |
b) CREATE TABLE IF NOT EXISTS syntax is not supported |
|---|
| 21 |
c) ALTER is not supported |
|---|
| 22 |
d) autoincrement is not supported |
|---|
| 23 |
|
|---|
| 24 |
There is a special sql file for sqlite, which generates identical to the |
|---|
| 25 |
standard file for mysql, execept of this changes: |
|---|
| 26 |
|
|---|
| 27 |
1) If tables already exists, the script will throw a lof of errors |
|---|
| 28 |
(as you are trying to create a table that already exists). |
|---|
| 29 |
|
|---|
| 30 |
2) The tables modules and Backup do not contain an auto incremental ID, |
|---|
| 31 |
and we will have to update the id on php code. |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
cat newinstall.sqlite.sql | sqlite /var/lib/freepbx/freepbx.db |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
2) Configuring freepbx to use sqlite and not mysql |
|---|
| 38 |
-------------------------------------------------- |
|---|
| 39 |
You will need to add a new entry in /etc/amportal.conf: |
|---|
| 40 |
|
|---|
| 41 |
AMPDBENGINE=sqlite |
|---|
| 42 |
|
|---|
| 43 |
This new entry, will cause the entries: |
|---|
| 44 |
AMPDBHOST |
|---|
| 45 |
AMPDBUSER |
|---|
| 46 |
AMPDBPASS |
|---|
| 47 |
|
|---|
| 48 |
Instead, you will have to supply a new entry: |
|---|
| 49 |
|
|---|
| 50 |
AMPDBFILE=/var/lib/freepbx/freepbx.db |
|---|
| 51 |
|
|---|
| 52 |
That's it. Be sure that apache (or whatever web server you are using) has |
|---|
| 53 |
write access to it. Usually, these commands will be enough: |
|---|
| 54 |
|
|---|
| 55 |
chown www-data.www-data /var/lib/freepbx/freepbx.db |
|---|
| 56 |
chmod g+rw /var/lib/freepbx/freepbx.db |
|---|
| 57 |
|
|---|
| 58 |
That's it. freepbx should now work. |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
3) Moving from sqlite back to mysql |
|---|
| 62 |
----------------------------------- |
|---|
| 63 |
I will not discuss here about importing and exporting the data, since this should |
|---|
| 64 |
be pretty trivial. |
|---|
| 65 |
|
|---|
| 66 |
You need to set AMPDBENGINE=mysql (or remark that line, as the default is to use |
|---|
| 67 |
mysql as on AMP). Do not forget to set the variables to define the connection: |
|---|
| 68 |
AMPDBHOST |
|---|
| 69 |
AMPDBUSER |
|---|
| 70 |
AMPDBPASS |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
4) Behind the scenes |
|---|
| 74 |
-------------------- |
|---|
| 75 |
If you are not interested about how this work is been done, you may ignore the rest |
|---|
| 76 |
of this document. |
|---|
| 77 |
|
|---|
| 78 |
One of the most important changes, is found in amp_conf/htdocs/admin/common/db_connect.php, were |
|---|
| 79 |
the creation of the database handle is created. If you are adding support for new connections |
|---|
| 80 |
this should be the first please to start coding. |
|---|
| 81 |
|
|---|
| 82 |
As reported on 1.d, sqlite2 does not support autoincrement. The affected tables are: |
|---|
| 83 |
modules and Backup. The function installModule on amp_conf/htdocs/admin/page.modules.php |
|---|
| 84 |
had to be changed, and in sqlite2 there is php code, that finds the biggest id available on |
|---|
| 85 |
that table, and then sets the new id as needed. |
|---|
| 86 |
|
|---|
| 87 |
There are some queries which use unsupported features as well. Some can be found at |
|---|
| 88 |
amp_conf/htdocs/admin/modules/core/functions.inc.php, core_trunks_list() |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
5) TODO |
|---|
| 92 |
------- |
|---|
| 93 |
a) The table Backup needs to be modified (no autoincrement support) |
|---|
| 94 |
b) Fix amp_conf/htdocs/admin/modules/core/functions.inc.php, core_trunks_list() |
|---|
| 95 |
c) Fix amp_conf/htdocs/admin/modules/core/functions.inc.php, core_routing_getroutenames() |
|---|
| 96 |
d) Find more problems and fix them! |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
6) Contact |
|---|
| 100 |
---------- |
|---|
| 101 |
If you have more questions, feel free to contact me, or post a message on the amportal-devel |
|---|
| 102 |
mailing list. |
|---|
| 103 |
|
|---|
| 104 |
amportal-devel@lists.sourceforge.net |
|---|
| 105 |
diego.iastrubni@xorcom.com |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
Diego |
|---|