Home > kalkun > Using Kalkun and gammu-smsd with SQLite3

Using Kalkun and gammu-smsd with SQLite3

It’s been a long time ago since i’ve started to thinking adding other database backend support besides MySQL. The problem is CodeIgniter (Kalkun is developed using CodeIgniter) and gammu-smsd both must support the database engine used, for example if CodeIgniter support PostgreSQL, than gammu-smsd must support PostgreSQL too, and so on. To make this dream comes true, i’ll have to “convert” all native SQL query to Codeigniter Active Record to make the query independent to all database engine because it’s handled by database driver.

Imagine that you want to install a software, but you only have SQLite3/PostgreSQL on your server, installing MySQL just for that can be huge problem. That’s the basic idea to support all database engine.

OK, for the first time, i’ve added SQLite3 support to Kalkun. But, it’s not as easy as i imagine to implement it. First, CodeIgniter doesn’t have official support for SQLite3, the driver only compatible with SQLite2, fortunately there’s community contribution that add SQLite3 through PDO (PHP Data Objects). So, you need pdo_sqlite extension on your PHP installation. Second, gammu-smsd also doesn’t have native support for sqlite3, otherwise it use libdbi.

Now let’s configure gammu-smsd to works with SQLite3 first. FYI, i’m using Mac OS X and gammu 1.29.0. Let’s install SQLite3 and libdbi drivers, i’m installing it using MacPorts.

$ sudo port install sqlite3
$ sudo port install libdbi
$ sudo port install libdbi-drivers

Next, compiling gammu with libdbi support. Make sure you get “Found libdbi: …” when running configure otherwise you can’t run gammu-smsd with SQLite3.

Create Kalkun database and import gammu database schema
Because of Kalkun New Installation, gammu database schema is not included on Kalkun source, now you’ve to import gammu database schema on your own (it’s included on gammu source eg. docs/sql/sqlite.sql). You can do the import using sqlite3 console:

$ sqlite3 kalkun.sqlite < docs/sql/sqlite.sql

or, if somehow it’s throw error “Error: near “/”: syntax error“, use this:

$ cat docs/sql/sqlite.sql | sqlite3 kalkun.sqlite

Or you can the import using SQLite3 client with GUI. I’m using SQLite Manager Firefox add-ons, off course you can use other SQLite client.

Next is import Kalkun database schema to the database, you can import it using your SQLite3 client or by Kalkun Installation. I’ll show you how to import using Kalkun installation. But before that you have to config the database first (it’s located on /application/config/database.php)

$db['default']['username'] = “”;
$db['default']['password'] = “”;
$db['default']['database'] = “sqlite:/path/to/database/kalkun.sqlite”;
$db['default']['dbdriver'] = “pdo”;

You only need to change the database path, SQLite doesn’t need username and password, and the driver should be pdo. It’s recommended to place your SQLite3 database outside your web root folder because of security issue.

Setting database permission, before launch Kalkun installation make sure the database is writable by web server user, you can give it world writable.

$ chmod 666 /path/to/sqlite3_db/
$ chmod 666 kalkun.sqlite

Next fire up Kalkun installation and choose SQLite3 on Database Setup.

Kalkun installation with SQLite3

Kalkun installation with SQLite3

Next, let’s configure gammu-smsd, open up your gammu-smsd configuration file a.k.a smsdrc

Service = SQL
Driver = sqlite3
database = kalkun.sqlite
dbdir = /path/to/sqlite3_db/

That’s all, now run your gammu-smsd, check logs and see if it’s working (no error). You can try sending SMS using gammu-smsd-inject:

$ gammu-smsd-inject TEXT 123456 -text “Hi, this is gammu sending using sqlite3″

Next, try sending SMS using Kalkun :D

..

PS: SQLite is famously knows for it’s liteness, but it’s may slower with network access and lots of activity/user using the same resource. So make sure you know what are you doing before using it.

Implemented on commit #fa845a4

Advertisement
Categories: kalkun Tags: , ,
  1. June 18, 2011 at 7:06 am | #1

    Hi!
    I’ve problems to setup kalkun with sqlite3. When I click on “Run database setup”
    I have this error:

    “——-
    A Database Error Occurred

    Error Number: 1

    near “)”: syntax error

    CREATE TABLE “user_group” ( “id_group” INTEGER PRIMARY KEY AUTOINCREMENT, “id_pbk” INTEGER NOT NULL, “id_pbk_groups” INTEGER NOT NULL, “id_user” INTEGER NOT NULL, );
    ——-”
    Do you have any idea?
    My system is Debian Lenny and Gammu 1.29.0.
    Thak you in advance. :)

  2. June 18, 2011 at 10:50 am | #2

    @Davide: Fixed on commit #7e77257. Thanks for reporting.

  3. June 23, 2011 at 7:37 am | #3

    Thank you Azhari!!!
    In the end I’ve got some problems. I decided to use mysql
    (with libdbd-mysql it works).
    Now I can send sms, but when I receve one, I have notification(see here http://i52.tinypic.com/f087md.jpg) but I can’t see the sms! It appears in in “inbox” table
    of the database but not in “user_inbox” table.

    Have you any idea?

    When I received a sms, in the shell that started gammu-sms
    appears these warning:
    debian:/home/davide# gammu-smsd -c /etc/gammu-smsdrc
    gammu-smsd[3423]: Process failed with exit status 127
    gammu-smsd[3423]: Process failed with exit status 127

    Thank you!! ;-)

  4. June 24, 2011 at 9:45 am | #4

    It means that the daemon (scripts/daemon.sh) failed to executed, try to run it manually. Make sure you’ve already configure the daemon.sh and daemon.php. Also make sure daemon.sh is executable, check permission.

  5. July 2, 2011 at 5:33 pm | #5

    Azhari Harahap :
    It means that the daemon (scripts/daemon.sh) failed to executed, try to run it manually. Make sure you’ve already configure the daemon.sh and daemon.php. Also make sure daemon.sh is executable, check permission.

    Thank you!!
    Now it’s all ok!!!
    I didn’t have the package php5-cli installed and the script daemon.sh was not configured!!

  6. August 17, 2011 at 8:14 am | #6

    Great tutorial. THanks

  7. bungsuputra linan
    December 11, 2011 at 1:19 am | #7

    I have successfully installed kalkun. I can also also do gammu-sms-inject and my message got sent successfully. I can receive new sms in kalkun, too. However, I still cannot send from inside kalkun.

    My configuration is:
    version: kalkun 0.40
    OS: ubuntu 10.04
    database type: sqlite3
    modem: huawei e220

    Is there a way to debug this problem?
    Thank you in advance.

  8. December 11, 2011 at 12:58 pm | #8

    bungsuputra linan :

    Is there a way to debug this problem?
    Thank you in advance.

    Try to activate gammu-smsd log, it seems that the problem is there.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.