| 1 |
SQLite3 support in freepbx |
|---|
| 2 |
-------------------------- |
|---|
| 3 |
|
|---|
| 4 |
If you are reading this, you should be aware that the support for sqlite3 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 SQLite3 on Debian Etch (version 3.3.8 or above), and not other versions. |
|---|
| 9 |
SQLite2 is deprecated, since it contains a lot of unsupported syntax (or does not support some mysql |
|---|
| 10 |
extensions widly used in freepbx) |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
1) Creating the initial tables |
|---|
| 14 |
------------------------------ |
|---|
| 15 |
The first step will be creating a default "database" for freepbx to use. We cannot use the |
|---|
| 16 |
standard newinstall.sql file, because of these reasons: |
|---|
| 17 |
|
|---|
| 18 |
a) Syntax for auto_increment is (for example) |
|---|
| 19 |
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT |
|---|
| 20 |
ALL OTHER FORMS WILL NOT WORK. Note that this code is supported |
|---|
| 21 |
by php5, but php4 does not like AUTOINCREMENT since it uses AUTO_INCREMENT. |
|---|
| 22 |
Look at the install.php of the freePBX modules to see a work-around. |
|---|
| 23 |
b) Only one primary key per table is supported |
|---|
| 24 |
c) ALTER is not supported (really? I am not sure) |
|---|
| 25 |
d) SUBSTRING is not supported |
|---|
| 26 |
e) enums are not supported |
|---|
| 27 |
|
|---|
| 28 |
There is a special sql file for sqlite3, which should be identical to the |
|---|
| 29 |
standard file for mysql, execept of this changes: |
|---|
| 30 |
|
|---|
| 31 |
1) some tables use string instead of enums |
|---|
| 32 |
2) all integers are "int" |
|---|
| 33 |
3) strings are "varchar" and not other types |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
To create the initial DB run this command: |
|---|
| 37 |
cat newinstall.sqlite.sql | sqlite3 /var/lib/asterisk/freepbx.db |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
2) Configuring freepbx to use sqlite3 instead of mysql |
|---|
| 41 |
------------------------------------------------------ |
|---|
| 42 |
You will need to add 2 new entries in /etc/amportal.conf: |
|---|
| 43 |
|
|---|
| 44 |
AMPDBENGINE=sqlite3 |
|---|
| 45 |
AMPDBFILE=/var/lib/asterisk/freepbx.db |
|---|
| 46 |
|
|---|
| 47 |
These new entries, will cause the following entries to be obsolete (you can safely remove them from amportal.conf/freepbx.conf): |
|---|
| 48 |
AMPDBHOST |
|---|
| 49 |
AMPDBUSER |
|---|
| 50 |
AMPDBPASS |
|---|
| 51 |
|
|---|
| 52 |
That's it. Be sure that apache (or whatever web server you are using) has |
|---|
| 53 |
write access to the sqlite3 databse file. Usually, these commands will be enough: |
|---|
| 54 |
|
|---|
| 55 |
chown www-data.www-data /var/lib/asterisk/freepbx.db |
|---|
| 56 |
chmod g+rw /var/lib/freepbx/freepbx.db |
|---|
| 57 |
|
|---|
| 58 |
You also must confirm that the web server has write access to the library |
|---|
| 59 |
as well: |
|---|
| 60 |
chown www-data.www-data /var/lib/asterisk/ |
|---|
| 61 |
chmod g+rw /var/lib/asterisk/ |
|---|
| 62 |
|
|---|
| 63 |
(Trixbox generally uses "asterisk" as the user for apache, so no special work is needed |
|---|
| 64 |
but this is will documented here) |
|---|
| 65 |
|
|---|
| 66 |
That's it. freepbx should now work. |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
3) Moving back from sqlite3 back to mysql |
|---|
| 70 |
----------------------------------------- |
|---|
| 71 |
I will not discuss here about importing and exporting the data, since this should |
|---|
| 72 |
be pretty trivial. |
|---|
| 73 |
|
|---|
| 74 |
You need to set AMPDBENGINE=mysql (or remark that line, as the default is to use |
|---|
| 75 |
mysql as on AMP). Do not forget to set the variables to define the connection: |
|---|
| 76 |
AMPDBHOST |
|---|
| 77 |
AMPDBUSER |
|---|
| 78 |
AMPDBPASS |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
4) Behind the scenes |
|---|
| 82 |
-------------------- |
|---|
| 83 |
If you are not interested about how this work is been done, you may ignore the rest |
|---|
| 84 |
of this document. |
|---|
| 85 |
|
|---|
| 86 |
One of the most important changes, is found in amp_conf/htdocs/admin/common/db_connect.php, were |
|---|
| 87 |
the creation of the database handle is created. If you are adding support for new connections |
|---|
| 88 |
this should be the first please to start coding. |
|---|
| 89 |
|
|---|
| 90 |
There are some queries which use unsupported features as well. Some can be found at |
|---|
| 91 |
amp_conf/htdocs/admin/modules/core/functions.inc.php, core_trunks_list(). Special cases |
|---|
| 92 |
have been made, and the code has been fixed in PHP (istead of SQL) |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
5) TODO |
|---|
| 96 |
------- |
|---|
| 97 |
a) as always, test, test, test.... |
|---|
| 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 |
|---|