DESCRIPTION

MYSQL backend stores all data in a MySQL database server, which parameters are defined by configuration (see gammu-smsdrc for description of configuration options).

For tables description see gammu-smsd-tables.

This backend is based on gammu-smsd-sql.

CONFIGURATION

Before running gammu-smsd you need to create necessary tables in the database, which is described bellow.

The configuration file then can look like:

[smsd]
service = sql
driver = native_mysql
host = localhost
See also

gammu-smsdrc

PRIVILEGES

The user accessing the database does not need much privileges, the following privleges should be enough:

GRANT USAGE ON *.* TO 'smsd'@'localhost' IDENTIFIED BY 'password';

GRANT SELECT, INSERT, UPDATE, DELETE ON \(gasmsd\(ga.* TO 'smsd'@'localhost';

NOTE: For creating the SQL tables you need more privileges, especially for creating triggers, which are used for some functionality.

CREATING TABLES

SQL script for creating tables in MySQL database:

-- phpMyAdmin SQL Dump
-- version 2.8.0.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 10, 2006 at 11:08 PM
-- Server version: 5.0.18
-- PHP Version: 5.1.3
--
-- Database: \(gasmsd\(ga
--

-- --------------------------------------------------------

--
-- Table structure for table \(gadaemons\(ga
--

CREATE TABLE \(gadaemons\(ga (
  \(gaStart\(ga text NOT NULL,
  \(gaInfo\(ga text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table \(gadaemons\(ga
--


-- --------------------------------------------------------

--
-- Table structure for table \(gagammu\(ga
--

CREATE TABLE \(gagammu\(ga (
  \(gaVersion\(ga integer NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table \(gagammu\(ga
--

INSERT INTO \(gagammu\(ga (\(gaVersion\(ga) VALUES (13);

-- --------------------------------------------------------

--
-- Table structure for table \(gainbox\(ga
--

CREATE TABLE \(gainbox\(ga (
  \(gaUpdatedInDB\(ga timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  \(gaReceivingDateTime\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaText\(ga text NOT NULL,
  \(gaSenderNumber\(ga varchar(20) NOT NULL default '',
  \(gaCoding\(ga enum('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression') NOT NULL default 'Default_No_Compression',
  \(gaUDH\(ga text NOT NULL,
  \(gaSMSCNumber\(ga varchar(20) NOT NULL default '',
  \(gaClass\(ga integer NOT NULL default '-1',
  \(gaTextDecoded\(ga text NOT NULL default '',
  \(gaID\(ga integer unsigned NOT NULL auto_increment,
  \(gaRecipientID\(ga text NOT NULL,
  \(gaProcessed\(ga enum('false','true') NOT NULL default 'false',
  PRIMARY KEY \(gaID\(ga (\(gaID\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table \(gainbox\(ga
--


-- --------------------------------------------------------

--
-- Table structure for table \(gaoutbox\(ga
--

CREATE TABLE \(gaoutbox\(ga (
  \(gaUpdatedInDB\(ga timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  \(gaInsertIntoDB\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaSendingDateTime\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaSendBefore\(ga time NOT NULL DEFAULT '23:59:59',
  \(gaSendAfter\(ga time NOT NULL DEFAULT '00:00:00',
  \(gaText\(ga text,
  \(gaDestinationNumber\(ga varchar(20) NOT NULL default '',
  \(gaCoding\(ga enum('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression') NOT NULL default 'Default_No_Compression',
  \(gaUDH\(ga text,
  \(gaClass\(ga integer default '-1',
  \(gaTextDecoded\(ga text NOT NULL default '',
  \(gaID\(ga integer unsigned NOT NULL auto_increment,
  \(gaMultiPart\(ga enum('false','true') default 'false',
  \(gaRelativeValidity\(ga integer default '-1',
  \(gaSenderID\(ga varchar(255),
  \(gaSendingTimeOut\(ga timestamp NULL default '0000-00-00 00:00:00',
  \(gaDeliveryReport\(ga enum('default','yes','no') default 'default',
  \(gaCreatorID\(ga text NOT NULL,
  PRIMARY KEY \(gaID\(ga (\(gaID\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE INDEX outbox_date ON outbox(SendingDateTime, SendingTimeOut);
CREATE INDEX outbox_sender ON outbox(SenderID);

--
-- Dumping data for table \(gaoutbox\(ga
--


-- --------------------------------------------------------

--
-- Table structure for table \(gaoutbox_multipart\(ga
--

CREATE TABLE \(gaoutbox_multipart\(ga (
  \(gaText\(ga text,
  \(gaCoding\(ga enum('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression') NOT NULL default 'Default_No_Compression',
  \(gaUDH\(ga text,
  \(gaClass\(ga integer default '-1',
  \(gaTextDecoded\(ga text default NULL,
  \(gaID\(ga integer unsigned NOT NULL default '0',
  \(gaSequencePosition\(ga integer NOT NULL default '1',
  PRIMARY KEY (\(gaID\(ga, \(gaSequencePosition\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table \(gaoutbox_multipart\(ga
--


-- --------------------------------------------------------

--
-- Table structure for table \(gapbk\(ga
--

CREATE TABLE \(gapbk\(ga (
  \(gaID\(ga integer NOT NULL auto_increment,
  \(gaGroupID\(ga integer NOT NULL default '-1',
  \(gaName\(ga text NOT NULL,
  \(gaNumber\(ga text NOT NULL,
  PRIMARY KEY (\(gaID\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table \(gapbk\(ga
--


-- --------------------------------------------------------

--
-- Table structure for table \(gapbk_groups\(ga
--

CREATE TABLE \(gapbk_groups\(ga (
  \(gaName\(ga text NOT NULL,
  \(gaID\(ga integer NOT NULL auto_increment,
  PRIMARY KEY \(gaID\(ga (\(gaID\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table \(gapbk_groups\(ga
--


-- --------------------------------------------------------

--
-- Table structure for table \(gaphones\(ga
--

CREATE TABLE \(gaphones\(ga (
  \(gaID\(ga text NOT NULL,
  \(gaUpdatedInDB\(ga timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  \(gaInsertIntoDB\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaTimeOut\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaSend\(ga enum('yes','no') NOT NULL default 'no',
  \(gaReceive\(ga enum('yes','no') NOT NULL default 'no',
  \(gaIMEI\(ga varchar(35) NOT NULL,
  \(gaClient\(ga text NOT NULL,
  \(gaBattery\(ga integer NOT NULL DEFAULT -1,
  \(gaSignal\(ga integer NOT NULL DEFAULT -1,
  \(gaSent\(ga int NOT NULL DEFAULT 0,
  \(gaReceived\(ga int NOT NULL DEFAULT 0,
  PRIMARY KEY (\(gaIMEI\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table \(gaphones\(ga
--

-- --------------------------------------------------------

--
-- Table structure for table \(gasentitems\(ga
--

CREATE TABLE \(gasentitems\(ga (
  \(gaUpdatedInDB\(ga timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  \(gaInsertIntoDB\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaSendingDateTime\(ga timestamp NOT NULL default '0000-00-00 00:00:00',
  \(gaDeliveryDateTime\(ga timestamp NULL,
  \(gaText\(ga text NOT NULL,
  \(gaDestinationNumber\(ga varchar(20) NOT NULL default '',
  \(gaCoding\(ga enum('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression') NOT NULL default 'Default_No_Compression',
  \(gaUDH\(ga text NOT NULL,
  \(gaSMSCNumber\(ga varchar(20) NOT NULL default '',
  \(gaClass\(ga integer NOT NULL default '-1',
  \(gaTextDecoded\(ga text NOT NULL default '',
  \(gaID\(ga integer unsigned NOT NULL default '0',
  \(gaSenderID\(ga varchar(255) NOT NULL,
  \(gaSequencePosition\(ga integer NOT NULL default '1',
  \(gaStatus\(ga enum('SendingOK','SendingOKNoReport','SendingError','DeliveryOK','DeliveryFailed','DeliveryPending','DeliveryUnknown','Error') NOT NULL default 'SendingOK',
  \(gaStatusError\(ga integer NOT NULL default '-1',
  \(gaTPMR\(ga integer NOT NULL default '-1',
  \(gaRelativeValidity\(ga integer NOT NULL default '-1',
  \(gaCreatorID\(ga text NOT NULL,
  PRIMARY KEY (\(gaID\(ga, \(gaSequencePosition\(ga)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE INDEX sentitems_date ON sentitems(DeliveryDateTime);
CREATE INDEX sentitems_tpmr ON sentitems(TPMR);
CREATE INDEX sentitems_dest ON sentitems(DestinationNumber);
CREATE INDEX sentitems_sender ON sentitems(SenderID);

--
-- Dumping data for table \(gasentitems\(ga
--


--
-- Triggers for setting default timestamps
--

DELIMITER //

CREATE TRIGGER inbox_timestamp BEFORE INSERT ON inbox
FOR EACH ROW
BEGIN
    IF NEW.ReceivingDateTime = '0000-00-00 00:00:00' THEN
        SET NEW.ReceivingDateTime = CURRENT_TIMESTAMP();
    END IF;
END;//

CREATE TRIGGER outbox_timestamp BEFORE INSERT ON outbox
FOR EACH ROW
BEGIN
    IF NEW.InsertIntoDB = '0000-00-00 00:00:00' THEN
        SET NEW.InsertIntoDB = CURRENT_TIMESTAMP();
    END IF;
    IF NEW.SendingDateTime = '0000-00-00 00:00:00' THEN
        SET NEW.SendingDateTime = CURRENT_TIMESTAMP();
    END IF;
    IF NEW.SendingTimeOut = '0000-00-00 00:00:00' THEN
        SET NEW.SendingTimeOut = CURRENT_TIMESTAMP();
    END IF;
END;//

CREATE TRIGGER phones_timestamp BEFORE INSERT ON phones
FOR EACH ROW
BEGIN
    IF NEW.InsertIntoDB = '0000-00-00 00:00:00' THEN
        SET NEW.InsertIntoDB = CURRENT_TIMESTAMP();
    END IF;
    IF NEW.TimeOut = '0000-00-00 00:00:00' THEN
        SET NEW.TimeOut = CURRENT_TIMESTAMP();
    END IF;
END;//

CREATE TRIGGER sentitems_timestamp BEFORE INSERT ON sentitems
FOR EACH ROW
BEGIN
    IF NEW.InsertIntoDB = '0000-00-00 00:00:00' THEN
        SET NEW.InsertIntoDB = CURRENT_TIMESTAMP();
    END IF;
    IF NEW.SendingDateTime = '0000-00-00 00:00:00' THEN
        SET NEW.SendingDateTime = CURRENT_TIMESTAMP();
    END IF;
END;//

DELIMITER ;


NOTE: You can find the script in docs/sql/mysql.sql as well.

UPGRADING TABLES

The easiest way to upgrade database structure is to backup old one and start with creating new one based on example above.

For upgrading existing database, you can use changes described in smsd-tables-history and then manually update Version field in gammu table.

AUTHOR

Michal Čihař <[email protected]>

COPYRIGHT

2009-2012, Michal Čihař <[email protected]>