Changeset 6277

Show
Ignore:
Timestamp:
08/02/08 22:59:08 (2 months ago)
Author:
ethans
Message:

Sqlite3-related fixes that have grown since 2.3. Closes #2987

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.5/announcement/install.php

    r6128 r6277  
    5454$repeat = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "repeat":"`repeat`"; 
    5555$sql = "SELECT $repeat FROM announcement"; 
    56 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
     56$check = @$db->getRow($sql, DB_FETCHMODE_ASSOC); 
    5757if(! DB::IsError($check)) { 
    5858    // Change field name because php5 was not happy with repeat 
  • modules/branches/2.5/backup/install.php

    r4767 r6277  
    55 
    66$autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; 
    7  
    8 $sql = " 
    9 CREATE TABLE IF NOT EXISTS Backup ( 
    10           Name varchar(50) default NULL, 
    11           Voicemail varchar(50) default NULL, 
    12           Recordings varchar(50) default NULL, 
    13           Configurations varchar(50) default NULL, 
    14           CDR varchar(55) default NULL, 
    15           FOP varchar(50) default NULL, 
    16           Minutes varchar(50) default NULL, 
    17           Hours varchar(50) default NULL, 
    18           Days varchar(50) default NULL, 
    19           Months varchar(50) default NULL, 
    20           Weekdays varchar(50) default NULL, 
    21           Command varchar(200) default NULL, 
    22           Method varchar(50) default NULL, 
    23           ID int(11) NOT NULL $autoincrement, 
    24           PRIMARY KEY  (ID) 
    25 );"; 
    26  
     7if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
     8        $sql = " 
     9        CREATE TABLE IF NOT EXISTS Backup ( 
     10                  Name varchar(50) default NULL, 
     11                  Voicemail varchar(50) default NULL, 
     12                  Recordings varchar(50) default NULL, 
     13                  Configurations varchar(50) default NULL, 
     14                  CDR varchar(55) default NULL, 
     15                  FOP varchar(50) default NULL, 
     16                  Minutes varchar(50) default NULL, 
     17                  Hours varchar(50) default NULL, 
     18                  Days varchar(50) default NULL, 
     19                  Months varchar(50) default NULL, 
     20                  Weekdays varchar(50) default NULL, 
     21                  Command varchar(200) default NULL, 
     22                  Method varchar(50) default NULL, 
     23                  ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT 
     24        ); 
     25        "; 
     26
     27else  { 
     28        $sql = " 
     29        CREATE TABLE IF NOT EXISTS Backup ( 
     30                  Name varchar(50) default NULL, 
     31                  Voicemail varchar(50) default NULL, 
     32                  Recordings varchar(50) default NULL, 
     33                  Configurations varchar(50) default NULL, 
     34                  CDR varchar(55) default NULL, 
     35                  FOP varchar(50) default NULL, 
     36                  Minutes varchar(50) default NULL, 
     37                  Hours varchar(50) default NULL, 
     38                  Days varchar(50) default NULL, 
     39                  Months varchar(50) default NULL, 
     40                  Weekdays varchar(50) default NULL, 
     41                  Command varchar(200) default NULL, 
     42                  Method varchar(50) default NULL, 
     43                  ID int(11) NOT NULL AUTO_INCREMENT, 
     44                  PRIMARY KEY  (ID) 
     45        ); 
     46        "; 
     47
    2748$check = $db->query($sql); 
    2849if(DB::IsError($check)) { 
  • modules/branches/2.5/cidlookup/install.php

    r5847 r6277  
    6767outn("Migrating channel routing to Zap DID routing.."); 
    6868$sql = "SELECT channel FROM cidlookup_incoming"; 
    69 $check = $db->query($sql); 
     69$check = @$db->query($sql); 
    7070if (!DB::IsError($check)) { 
    7171        $chan_prefix = 'zapchan'; 
     
    7676        } else { 
    7777                out("OK"); 
    78                 outn("Removing deprecated channel field from incoming.."); 
    79                 $sql = "ALTER TABLE cidlookup_incoming DROP channel"; 
    80                 $results = $db->query($sql); 
    81                 if (DB::IsError($results)) {  
     78                // ALTER...DROP is not supported by sqlite3.  This table was setup properly in the CREATE anyway 
     79                if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     80                        outn("Removing deprecated channel field from incoming.."); 
     81                        $sql = "ALTER TABLE cidlookup_incoming DROP channel"; 
     82                        $results = $db->query($sql); 
     83                        if (DB::IsError($results)) {  
    8284                        out("ERROR: failed: ".$results->getMessage()); 
    83                 } else { 
    84                         out("OK"); 
     85                        } else { 
     86                                out("OK"); 
     87                        } 
    8588                } 
    8689        } 
     
    9295// this should maybe be added to core as well 
    9396// 
    94 outn("Checking for cidlookup field in core's incoming table.."); 
    95 $sql = "ALTER TABLE incoming DROP cidlookup"; 
    96 $results = $db->query($sql); 
    97 if (DB::IsError($results)) {  
    98         out("not present"); 
    99 } else { 
     97// ALTER...DROP is not supported by sqlite3.  This table was setup properly in the CREATE anyway 
     98if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     99 
     100        outn("Checking for cidlookup field in core's incoming table.."); 
     101        $sql = "ALTER TABLE incoming DROP cidlookup"; 
     102        $results = $db->query($sql); 
     103        if (DB::IsError($results)) {  
     104                out("not present"); 
     105        } else { 
    100106        out("removed"); 
     107        } 
    101108} 
    102  
    103109?> 
    104110 
  • modules/branches/2.5/customerdb/install.php

    r6136 r6277  
    1515global $amp_conf; 
    1616 
    17 $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; 
    18 $sql = " 
    19 CREATE TABLE IF NOT EXISTS customerdb  
    20 
    21         `id` int UNIQUE  $autoincrement,  
    22         `name` varchar(45) not null,  
    23         `addr1` varchar(150) not null,   
    24         `addr2` varchar(150) null,  
    25         `city` varchar(50) not null,  
    26         `state` varchar(5) not null,  
    27         `zip` varchar(12) null,  
    28         `sip` varchar(20) null,  
    29         `did` varchar(45) null,  
    30         `device` varchar(50) null,  
    31         `ip` varchar(20) null,  
    32         `serial` varchar(50) null,  
    33         `account` varchar(6) null,  
    34         `email` varchar(150) null,  
    35         `username` varchar(25) null,  
    36         `password` varchar(25) null 
    37 ); 
    38 "; 
     17if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
     18        $sql = " 
     19        CREATE TABLE IF NOT EXISTS customerdb  
     20        ( 
     21                `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
     22                `name` varchar(45) not null,  
     23                `addr1` varchar(150) not null,   
     24                `addr2` varchar(150) null,  
     25                `city` varchar(50) not null,  
     26                `state` varchar(5) not null,  
     27                `zip` varchar(12) null,  
     28                `sip` varchar(20) null,  
     29                `did` varchar(45) null,  
     30                `device` varchar(50) null,  
     31                `ip` varchar(20) null,  
     32                `serial` varchar(50) null,  
     33                `account` varchar(6) null,  
     34                `email` varchar(150) null,  
     35                `username` varchar(25) null,  
     36                `password` varchar(25) null 
     37        ); 
     38        "; 
     39
     40else  { 
     41        $sql = " 
     42        CREATE TABLE IF NOT EXISTS customerdb  
     43        ( 
     44                `id` int UNIQUE AUTO_INCREMENT,   
     45                `name` varchar(45) not null,  
     46                `addr1` varchar(150) not null,   
     47                `addr2` varchar(150) null,  
     48                `city` varchar(50) not null,  
     49                `state` varchar(5) not null,  
     50                `zip` varchar(12) null,  
     51                `sip` varchar(20) null,  
     52                `did` varchar(45) null,  
     53                `device` varchar(50) null,  
     54                `ip` varchar(20) null,  
     55                `serial` varchar(50) null,  
     56                `account` varchar(6) null,  
     57                `email` varchar(150) null,  
     58                `username` varchar(25) null,  
     59                `password` varchar(25) null 
     60        ); 
     61        "; 
     62
    3963$check = $db->query($sql); 
    4064if(DB::IsError($check)) { 
  • modules/branches/2.5/findmefollow/install.php

    r6158 r6277  
    8686    if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 
    8787} 
    88 // increase size for older installs 
    89 $db->query("ALTER TABLE findmefollow CHANGE dring dring VARCHAR( 255 ) NULL"); 
    90  
     88// increase size for older installs, ignore sqlite3, doesn't support ALTER...CHANGE syntax, table created properly above 
     89if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     90        $db->query("ALTER TABLE findmefollow CHANGE dring dring VARCHAR( 255 ) NULL"); 
     91
    9192$results = array(); 
    9293$sql = "SELECT grpnum, postdest FROM findmefollow"; 
     
    138139 
    139140// Version 2.4.13 change (#1961) 
    140 // 
    141 $results = $db->query("ALTER TABLE `findmefollow` CHANGE `grpnum` `grpnum` VARCHAR( 20 ) NOT NULL"); 
    142 if(DB::IsError($results)) { 
    143         echo $results->getMessage(); 
    144         return false; 
     141// Ignore sqlite3, doesn't support ALTER...CHANGE syntax, table created properly above 
     142if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     143        $sql = "ALTER TABLE `findmefollow` CHANGE `grpnum` `grpnum` VARCHAR( 20 ) NOT NULL"; 
     144        $results = $db->query($sql); 
     145        if(DB::IsError($results)) { 
     146                echo $results->getMessage(); 
     147                return false; 
     148        } 
    145149} 
    146150 
     
    148152// 
    149153outn(_("Checking if recordings need migration..")); 
    150 $sql = "SELECT annmsg_id FROM findmefollow"; 
    151 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    152 if(DB::IsError($check)) { 
    153         //  Add recording_id field 
    154         // 
    155         out("migrating"); 
    156         outn(_("adding annmsg_id field..")); 
    157   $sql = "ALTER TABLE findmefollow ADD annmsg_id INTEGER"; 
    158   $result = $db->query($sql); 
    159   if(DB::IsError($result)) { 
    160                 out(_("fatal error")); 
    161                 die_freepbx($result->getDebugInfo());  
     154// Do not do upgrades for sqlite3.  Assume full support begins in 2.5 and our CREATE syntax is correct 
     155if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     156        $sql = "SELECT annmsg_id FROM findmefollow"; 
     157        $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
     158        if(DB::IsError($check)) { 
     159                //  Add recording_id field 
     160                // 
     161                out("migrating");        
     162                outn(_("adding annmsg_id field..")); 
     163        $sql = "ALTER TABLE findmefollow ADD annmsg_id INTEGER"; 
     164        $result = $db->query($sql); 
     165        if(DB::IsError($result)) { 
     166                        out(_("fatal error")); 
     167                        die_freepbx($result->getDebugInfo());    
     168                } else { 
     169                        out(_("ok")); 
     170                } 
     171                outn(_("adding remotealert_id field..")); 
     172        $sql = "ALTER TABLE findmefollow ADD remotealert_id INTEGER"; 
     173        $result = $db->query($sql); 
     174        if(DB::IsError($result)) { 
     175                        out(_("fatal error")); 
     176                        die_freepbx($result->getDebugInfo());  
     177                } else { 
     178                        out(_("ok")); 
     179                } 
     180                outn(_("adding toolate_id field..")); 
     181                $sql = "ALTER TABLE findmefollow ADD toolate_id INTEGER"; 
     182                  $result = $db->query($sql); 
     183                 if(DB::IsError($result)) { 
     184                                out(_("fatal error")); 
     185                                die_freepbx($result->getDebugInfo());  
     186                        } else { 
     187                                out(_("ok")); 
     188                        } 
     189 
     190                // Get all the valudes and replace them with recording_id 
     191                // 
     192                outn(_("migrate annmsg to ids..")); 
     193         $sql = "SELECT `grpnum`, `annmsg` FROM `findmefollow`"; 
     194                $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     195                if(DB::IsError($results)) { 
     196                        out(_("fatal error")); 
     197                        die_freepbx($results->getDebugInfo());   
     198                } 
     199                $migrate_arr = array(); 
     200                $count = 0; 
     201                foreach ($results as $row) { 
     202                        if (trim($row['annmsg']) != '') { 
     203                                $rec_id = recordings_get_or_create_id($row['annmsg'], 'findmefollow'); 
     204                                $migrate_arr[] = array($rec_id, $row['grpnum']); 
     205                                $count++; 
     206                        } 
     207                } 
     208                if ($count) { 
     209                        $compiled = $db->prepare('UPDATE `findmefollow` SET `annmsg_id` = ? WHERE `grpnum` = ?'); 
     210                        $result = $db->executeMultiple($compiled,$migrate_arr); 
     211                        if(DB::IsError($result)) { 
     212                                out(_("fatal error")); 
     213                                die_freepbx($result->getDebugInfo());    
     214                        } 
     215                } 
     216                out(sprintf(_("migrated %s entries"),$count)); 
     217 
     218                outn(_("migrate remotealert to ids..")); 
     219        $sql = "SELECT `grpnum`, `remotealert` FROM `findmefollow`"; 
     220                $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     221                if(DB::IsError($results)) { 
     222                        out(_("fatal error")); 
     223                        die_freepbx($results->getDebugInfo());   
     224                } 
     225                $migrate_arr = array(); 
     226                $count = 0; 
     227                foreach ($results as $row) { 
     228                        if (trim($row['remotealert']) != '') { 
     229                                $rec_id = recordings_get_or_create_id($row['remotealert'], 'findmefollow'); 
     230                                $migrate_arr[] = array($rec_id, $row['grpnum']); 
     231                                $count++; 
     232                        } 
     233                } 
     234                if ($count) { 
     235                        $compiled = $db->prepare('UPDATE `findmefollow` SET `remotealert_id` = ? WHERE `grpnum` = ?'); 
     236                        $result = $db->executeMultiple($compiled,$migrate_arr); 
     237                        if(DB::IsError($result)) { 
     238                                out(_("fatal error")); 
     239                                die_freepbx($result->getDebugInfo());    
     240                        } 
     241                } 
     242                out(sprintf(_("migrated %s entries"),$count));   
     243 
     244                outn(_("migrate toolate to  ids..")); 
     245         $sql = "SELECT `grpnum`, `toolate` FROM `findmefollow`"; 
     246                $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     247                if(DB::IsError($results)) { 
     248                        out(_("fatal error")); 
     249                        die_freepbx($results->getDebugInfo());   
     250                } 
     251                $migrate_arr = array(); 
     252                $count = 0; 
     253                foreach ($results as $row) { 
     254                        if (trim($row['toolate']) != '') { 
     255                                $rec_id = recordings_get_or_create_id($row['toolate'], 'findmefollow'); 
     256                                $migrate_arr[] = array($rec_id, $row['grpnum']); 
     257                                $count++; 
     258                        } 
     259                } 
     260                if ($count) { 
     261                        $compiled = $db->prepare('UPDATE `findmefollow` SET `toolate_id` = ? WHERE `grpnum` = ?'); 
     262                        $result = $db->executeMultiple($compiled,$migrate_arr); 
     263                        if(DB::IsError($result)) { 
     264                                out(_("fatal error")); 
     265                                die_freepbx($result->getDebugInfo());    
     266                        } 
     267                } 
     268                out(sprintf(_("migrated %s entries"),$count)); 
     269 
     270                // Now remove the old recording field replaced by new id field 
     271                // 
     272                outn(_("dropping annmsg field..")); 
     273        $sql = "ALTER TABLE `findmefollow` DROP `annmsg`"; 
     274        $result = $db->query($sql); 
     275        if(DB::IsError($result)) {  
     276                        out(_("no annmsg field???")); 
     277                } else { 
     278                        out(_("ok")); 
     279                } 
     280                outn(_("dropping remotealert field..")); 
     281          $sql = "ALTER TABLE `findmefollow` DROP `remotealert`"; 
     282         $result = $db->query($sql); 
     283        if(DB::IsError($result)) {  
     284                        out(_("no remotealert field???")); 
     285                } else { 
     286                        out(_("ok")); 
     287                } 
     288                outn(_("dropping toolate field..")); 
     289         $sql = "ALTER TABLE `findmefollow` DROP `toolate`"; 
     290        $result = $db->query($sql); 
     291        if(DB::IsError($result)) {  
     292                        out(_("no toolate field???")); 
     293                } else { 
     294                        out(_("ok")); 
     295                } 
     296 
    162297        } else { 
    163                 out(_("ok")); 
    164         } 
    165         outn(_("adding remotealert_id field..")); 
    166   $sql = "ALTER TABLE findmefollow ADD remotealert_id INTEGER"; 
    167   $result = $db->query($sql); 
    168   if(DB::IsError($result)) { 
    169                 out(_("fatal error")); 
    170                 die_freepbx($result->getDebugInfo());  
    171         } else { 
    172                 out(_("ok")); 
    173         } 
    174         outn(_("adding toolate_id field..")); 
    175   $sql = "ALTER TABLE findmefollow ADD toolate_id INTEGER"; 
    176   $result = $db->query($sql); 
    177   if(DB::IsError($result)) { 
    178                 out(_("fatal error")); 
    179                 die_freepbx($result->getDebugInfo());  
    180         } else { 
    181                 out(_("ok")); 
    182         } 
    183  
    184         // Get all the valudes and replace them with recording_id 
    185         // 
    186         outn(_("migrate annmsg to ids..")); 
    187   $sql = "SELECT `grpnum`, `annmsg` FROM `findmefollow`"; 
    188         $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    189         if(DB::IsError($results)) { 
    190                 out(_("fatal error")); 
    191                 die_freepbx($results->getDebugInfo());   
    192         } 
    193         $migrate_arr = array(); 
    194         $count = 0; 
    195         foreach ($results as $row) { 
    196                 if (trim($row['annmsg']) != '') { 
    197                         $rec_id = recordings_get_or_create_id($row['annmsg'], 'findmefollow'); 
    198                         $migrate_arr[] = array($rec_id, $row['grpnum']); 
    199                         $count++; 
    200                 } 
    201         } 
    202         if ($count) { 
    203                 $compiled = $db->prepare('UPDATE `findmefollow` SET `annmsg_id` = ? WHERE `grpnum` = ?'); 
    204                 $result = $db->executeMultiple($compiled,$migrate_arr); 
    205                 if(DB::IsError($result)) { 
    206                         out(_("fatal error")); 
    207                         die_freepbx($result->getDebugInfo());    
    208                 } 
    209         } 
    210         out(sprintf(_("migrated %s entries"),$count)); 
    211  
    212         outn(_("migrate remotealert to ids..")); 
    213   $sql = "SELECT `grpnum`, `remotealert` FROM `findmefollow`"; 
    214         $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    215         if(DB::IsError($results)) { 
    216                 out(_("fatal error")); 
    217                 die_freepbx($results->getDebugInfo());   
    218         } 
    219         $migrate_arr = array(); 
    220         $count = 0; 
    221         foreach ($results as $row) { 
    222                 if (trim($row['remotealert']) != '') { 
    223                         $rec_id = recordings_get_or_create_id($row['remotealert'], 'findmefollow'); 
    224                         $migrate_arr[] = array($rec_id, $row['grpnum']); 
    225                         $count++; 
    226                 } 
    227         } 
    228         if ($count) { 
    229                 $compiled = $db->prepare('UPDATE `findmefollow` SET `remotealert_id` = ? WHERE `grpnum` = ?'); 
    230                 $result = $db->executeMultiple($compiled,$migrate_arr); 
    231                 if(DB::IsError($result)) { 
    232                         out(_("fatal error")); 
    233                         die_freepbx($result->getDebugInfo());    
    234                 } 
    235         } 
    236         out(sprintf(_("migrated %s entries"),$count)); 
    237  
    238         outn(_("migrate toolate to  ids..")); 
    239   $sql = "SELECT `grpnum`, `toolate` FROM `findmefollow`"; 
    240         $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    241         if(DB::IsError($results)) { 
    242                 out(_("fatal error")); 
    243                 die_freepbx($results->getDebugInfo());   
    244         } 
    245         $migrate_arr = array(); 
    246         $count = 0; 
    247         foreach ($results as $row) { 
    248                 if (trim($row['toolate']) != '') { 
    249                         $rec_id = recordings_get_or_create_id($row['toolate'], 'findmefollow'); 
    250                         $migrate_arr[] = array($rec_id, $row['grpnum']); 
    251                         $count++; 
    252                 } 
    253         } 
    254         if ($count) { 
    255                 $compiled = $db->prepare('UPDATE `findmefollow` SET `toolate_id` = ? WHERE `grpnum` = ?'); 
    256                 $result = $db->executeMultiple($compiled,$migrate_arr); 
    257                 if(DB::IsError($result)) { 
    258                         out(_("fatal error")); 
    259                         die_freepbx($result->getDebugInfo());    
    260                 } 
    261         } 
    262         out(sprintf(_("migrated %s entries"),$count)); 
    263  
    264         // Now remove the old recording field replaced by new id field 
    265         // 
    266         outn(_("dropping annmsg field..")); 
    267   $sql = "ALTER TABLE `findmefollow` DROP `annmsg`"; 
    268   $result = $db->query($sql); 
    269   if(DB::IsError($result)) {  
    270                 out(_("no annmsg field???")); 
    271         } else { 
    272                 out(_("ok")); 
    273         } 
    274         outn(_("dropping remotealert field..")); 
    275   $sql = "ALTER TABLE `findmefollow` DROP `remotealert`"; 
    276   $result = $db->query($sql); 
    277   if(DB::IsError($result)) {  
    278                 out(_("no remotealert field???")); 
    279         } else { 
    280                 out(_("ok")); 
    281         } 
    282         outn(_("dropping toolate field..")); 
    283   $sql = "ALTER TABLE `findmefollow` DROP `toolate`"; 
    284   $result = $db->query($sql); 
    285   if(DB::IsError($result)) {  
    286                 out(_("no toolate field???")); 
    287         } else { 
    288                 out(_("ok")); 
    289         } 
    290  
    291 } else { 
    292         out("already migrated"); 
     298                out("already migrated"); 
     299        } 
    293300} 
    294301 
  • modules/branches/2.5/ivr/install.php

    r6184 r6277  
    1616global $amp_conf; 
    1717 
    18 $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; 
    19 $sql = " 
    20 CREATE TABLE IF NOT EXISTS ivr  
    21 (  
    22         `ivr_id` INT NOT NULL $autoincrement PRIMARY KEY,  
    23         `displayname` VARCHAR(50),  
    24         `deptname` VARCHAR(50),  
    25         `enable_directory` VARCHAR(8),  
    26         `enable_directdial` VARCHAR(8),  
    27         `timeout` INT,  
    28         `announcement` VARCHAR(255),  
    29         `dircontext` VARCHAR ( 50 ) DEFAULT 'default',  
    30         `alt_timeout` VARCHAR(8),  
    31         `alt_invalid` VARCHAR(8),  
    32         `loops` TINYINT(1) NOT NULL DEFAULT 2  
    33 
    34 "; 
     18if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
     19        $sql = " 
     20                CREATE TABLE IF NOT EXISTS ivr (  
     21                        ivr_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,  
     22                        displayname VARCHAR(50),  
     23                        deptname VARCHAR(50),  
     24                        enable_directory VARCHAR(8),  
     25                        enable_directdial VARCHAR(8),  
     26                        timeout INT,  
     27                        announcement VARCHAR(255),  
     28                        dircontext VARCHAR ( 50 ) DEFAULT 'default',  
     29                        alt_timeout VARCHAR(8),  
     30                        alt_invalid VARCHAR(8),  
     31                        `loops` TINYINT(1) NOT NULL DEFAULT 2 
     32                ); 
     33        "; 
     34
     35else  { 
     36        $sql = " 
     37                CREATE TABLE IF NOT EXISTS ivr (  
     38                        ivr_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY  ,  
     39                        displayname VARCHAR(50),  
     40                        deptname VARCHAR(50),  
     41                        enable_directory VARCHAR(8),  
     42                        enable_directdial VARCHAR(8),  
     43                        timeout INT,  
     44                        announcement VARCHAR(255),  
     45                        dircontext VARCHAR ( 50 ) DEFAULT 'default',  
     46                        alt_timeout VARCHAR(8),  
     47                        alt_invalid VARCHAR(8),  
     48                        `loops` TINYINT(1) NOT NULL DEFAULT 2 
     49                ); 
     50        "; 
     51
    3552sql($sql); 
    3653 
  • modules/branches/2.5/paging/install.php

    r5770 r6277  
    11<?php 
    2  
     2global $amp_conf; 
    33// Enable intercom as a feature code 
    44$fcc = new featurecode('paging', 'intercom-prefix'); 
     
    130130// Make sure primary keys are set, they were not originally. Don't check for error, 
    131131// if they exist it will give an error 
    132 // 
    133 $sql = "ALTER TABLE `paging_groups` ADD PRIMARY KEY ( `page_number` , `ext` )"; 
    134 $result = $db->query($sql); 
     132// sqlite3 does not support adding keys after the fact with ALTER. 
     133// These keys are setup in the CREATE TABLE as of 2.5 anyway, so 
     134// just ignore these queries for sqlite3 
     135if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     136        $sql = "ALTER TABLE `paging_groups` ADD PRIMARY KEY ( `page_number` , `ext` )"; 
     137        $result = $db->query($sql); 
    135138 
    136 $sql = "ALTER TABLE `paging_config` ADD PRIMARY KEY ( `page_group` )"; 
    137 $result = $db->query($sql); 
    138  
     139       $sql = "ALTER TABLE `paging_config` ADD PRIMARY KEY ( `page_group` )"; 
     140       $result = $db->query($sql); 
     141
    139142?> 
  • modules/branches/2.5/queues/install.php

    r6247 r6277  
    11<?php 
    22global $db; 
    3  
     3global $amp_conf; 
    44if (! function_exists("out")) { 
    55        function out($text) { 
     
    112112        // can get the status in the error 
    113113        // 
    114         $sql = " 
    115         CREATE TABLE queues_config ( 
    116           extension varchar(20) NOT NULL default '', 
    117           descr varchar(35) NOT NULL default '', 
    118           grppre varchar(100) NOT NULL default '', 
    119           alertinfo varchar(254) NOT NULL default '', 
    120           joinannounce varchar(254) NOT NULL default '', 
    121           ringing tinyint(1) NOT NULL default '0', 
    122           agentannounce varchar(254) NOT NULL default '', 
    123           maxwait varchar(8) NOT NULL default '', 
    124           `password` varchar(20) NOT NULL default '', 
    125           ivr_id varchar(8) NOT NULL default '0', 
    126           dest varchar(50) NOT NULL default '', 
    127           cwignore tinyint(1) NOT NULL default '0', 
    128         PRIMARY KEY  (extension) 
    129         )"; 
     114        // for sqlite3, create the final table template since sqlite3  
     115        // support officially begins at 2.5 release. 
     116        if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
     117 
     118                $sql = " 
     119                CREATE TABLE IF NOT EXISTS queues_config ( 
     120                  extension varchar(20) NOT NULL default '', 
     121                  descr varchar(35) NOT NULL default '', 
     122                  grppre varchar(100) NOT NULL default '', 
     123                  alertinfo varchar(254) NOT NULL default '', 
     124                  ringing tinyint(1) NOT NULL default '0', 
     125                  maxwait varchar(8) NOT NULL default '', 
     126                  `password` varchar(20) NOT NULL default '', 
     127                  ivr_id varchar(8) NOT NULL default '0', 
     128                  dest varchar(50) NOT NULL default '', 
     129                  cwignore tinyint(1) NOT NULL default '0', 
     130                  `qregex` VARCHAR( 255 ) NULL, 
     131                PRIMARY KEY  (extension) 
     132                ) 
     133                "; 
     134        } 
     135        else  { 
     136                $sql = " 
     137                CREATE TABLE queues_config ( 
     138                  extension varchar(20) NOT NULL default '', 
     139                  descr varchar(35) NOT NULL default '', 
     140                  grppre varchar(100) NOT NULL default '', 
     141                  alertinfo varchar(254) NOT NULL default '', 
     142                  joinannounce varchar(254) NOT NULL default '', 
     143                  ringing tinyint(1) NOT NULL default '0', 
     144                  agentannounce varchar(254) NOT NULL default '', 
     145                  maxwait varchar(8) NOT NULL default '', 
     146                  `password` varchar(20) NOT NULL default '', 
     147                  ivr_id varchar(8) NOT NULL default '0', 
     148                  dest varchar(50) NOT NULL default '', 
     149                  cwignore tinyint(1) NOT NULL default '0', 
     150                PRIMARY KEY  (extension) 
     151                ) 
     152                "; 
     153 
     154        } 
    130155 
    131156        outn(_("Creating queues_config..")); 
     
    406431        // 
    407432        outn(_("dropping agentannounce field..")); 
    408   $sql = "ALTER TABLE `queues_config` DROP `agentannounce`"; 
    409   $result = $db->query($sql); 
    410   if(DB::IsError($result)) {  
    411                 out(_("no agentannounce field???")); 
    412         } else { 
    413                 out(_("ok")); 
    414         } 
    415         outn(_("dropping joinannounce field..")); 
    416   $sql = "ALTER TABLE `queues_config` DROP `joinannounce`"; 
    417   $result = $db->query($sql); 
    418   if(DB::IsError($result)) {  
    419                 out(_("no joinannounce field???")); 
    420         } else { 
    421                 out(_("ok")); 
    422         } 
    423 } else { 
    424         out("already migrated"); 
    425 
     433  // sqlite doesn't support drop syntax, but since we already CREATE'd the table properly, these don't need to be executed anyway 
     434  if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     435          $sql = "ALTER TABLE `queues_config` DROP `agentannounce`"; 
     436         $result = $db->query($sql); 
     437          if(DB::IsError($result)) {  
     438                        out(_("no agentannounce field???")); 
     439                } else { 
     440                        out(_("ok")); 
     441                } 
     442                outn(_("dropping joinannounce field..")); 
     443          $sql = "ALTER TABLE `queues_config` DROP `joinannounce`"; 
     444          $result = $db->query($sql); 
     445          if(DB::IsError($result)) {  
     446                        out(_("no joinannounce field???")); 
     447                } else { 
     448                        out(_("ok")); 
     449                } 
     450        } else { 
     451                out("already migrated"); 
     452        } 
     453  } 
    426454 
    427455outn(_("checking for queuewait field..")); 
  • modules/branches/2.5/recordings/install.php

    r5982 r6277  
    3737 
    3838// Make sure table exists 
    39 $sql = "CREATE TABLE IF NOT EXISTS recordings (  
    40         id INTEGER NOT NULL  PRIMARY KEY $autoincrement, 
    41         displayname VARCHAR(50) ,  
    42         filename BLOB,  
    43         description VARCHAR(254)) 
    44 ;"; 
     39if ($amp_conf["AMPDBENGINE"] == 'sqlite3') { 
     40        $sql = "CREATE TABLE IF NOT EXISTS recordings (  
     41                `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,  
     42                displayname VARCHAR(50) , filename BLOB, description  
     43                VARCHAR(254)) 
     44        ;"; 
     45}  else  { 
     46        $sql = "CREATE TABLE IF NOT EXISTS recordings (  
     47                id INTEGER NOT NULL  PRIMARY KEY $autoincrement, 
     48                displayname VARCHAR(50) ,  
     49                filename BLOB,  
     50                description VARCHAR(254)) 
     51        ;"; 
     52
    4553$result = $db->query($sql); 
    4654if(DB::IsError($result)) { 
  • modules/branches/2.5/timeconditions/install.php

    r6217 r6277  
    1818} 
    1919 
    20 $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; 
    21  
    22 $sql = " 
    23 CREATE TABLE IF NOT EXISTS timeconditions ( 
    24         timeconditions_id INTEGER NOT NULL PRIMARY KEY $autoincrement, 
    25         displayname VARCHAR( 50 ) , 
    26         time INT ( 11 ) , 
    27         truegoto VARCHAR( 50 ) , 
    28         falsegoto VARCHAR( 50 ), 
    29         deptname VARCHAR( 50 ) 
    30 )"; 
     20if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
     21        $sql = " 
     22        CREATE TABLE IF NOT EXISTS timeconditions ( 
     23                `timeconditions_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
     24                `displayname` VARCHAR( 50 ) , 
     25                `time` INT( 11 ) , 
     26                `truegoto` VARCHAR( 50 ) , 
     27                `falsegoto` VARCHAR( 50 ), 
     28                `deptname` VARCHAR( 50 ) 
     29        ) 
     30        "; 
     31
     32else  { 
     33        $sql = " 
     34        CREATE TABLE IF NOT EXISTS timeconditions ( 
     35                `timeconditions_id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
     36                `displayname` VARCHAR( 50 ) , 
     37                `time` INT( 11 ) , 
     38                `truegoto` VARCHAR( 50 ) , 
     39                `falsegoto` VARCHAR( 50 ), 
     40                `deptname` VARCHAR( 50 ) 
     41        ) 
     42        "; 
     43
    3144$check = $db->query($sql); 
    3245if(DB::IsError($check)) { 
    3346                die_freepbx("Can not create `timeconditions` table: " .  $check->getMessage() .  "\n"); 
    3447} 
     48if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
    3549 
    36 $sql = " 
    37 CREATE TABLE IF NOT EXISTS `timegroups_groups` ( 
    38   `id` int(11) NOT NULL PRIMARY KEY $autoincrement, 
    39   `description` varchar(50) NOT NULL default '', 
    40   UNIQUE KEY `display` (`description`) 
    41 ) $autoincrement = 1  
    42 "; 
     50        $sql = " 
     51        CREATE TABLE IF NOT EXISTS `timegroups_groups` ( 
     52                `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
     53                `description` varchar(50) NOT NULL default '', 
     54                UNIQUE (`description`) 
     55        )        
     56        "; 
     57
     58else  { 
     59        $sql = " 
     60        CREATE TABLE IF NOT EXISTS `timegroups_groups` ( 
     61                `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, 
     62                `description` varchar(50) NOT NULL default '', 
     63                 UNIQUE KEY `display` (`description`) 
     64        ) AUTO_INCREMENT = 1  
     65        "; 
     66
    4367$check = $db->query($sql); 
    4468if(DB::IsError($check)) { 
     
    4670} 
    4771 
    48 $sql = " 
    49 CREATE TABLE IF NOT EXISTS `timegroups_details` ( 
    50   `id` int(11) NOT NULL PRIMARY KEY $autoincrement, 
    51   `timegroupid` int(11) NOT NULL default '0', 
    52   `time` varchar(100) NOT NULL default '' 
    53 ) $autoincrement = 1  
    54 "; 
     72if($amp_conf["AMPDBENGINE"] == "sqlite3")  { 
     73 
     74        $sql = " 
     75        CREATE TABLE IF NOT EXISTS `timegroups_details` ( 
     76                `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
     77                `timegroupid` int(11) NOT NULL default '0', 
     78                `time` varchar(100) NOT NULL default '' 
     79        )  
     80        "; 
     81
     82else  { 
     83        $sql = " 
     84        CREATE TABLE IF NOT EXISTS `timegroups_details` ( 
     85                `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, 
     86                `timegroupid` int(11) NOT NULL default '0', 
     87                `time` varchar(100) NOT NULL default '' 
     88        ) 
     89        "; 
     90
    5591$check = $db->query($sql); 
    5692if(DB::IsError($check)) { 
     
    89125 */ 
    90126outn(_("converting timeconditions time field to int..")); 
    91 $sql = "ALTER TABLE `timeconditions` CHANGE `time` `time` INT (11)"; 
    92 $results = $db->query($sql); 
    93 if(DB::IsError($results)) { 
    94         out(_("ERROR: failed to convert field ").$results->getMessage()); 
    95 } else { 
    96         out(_("OK")); 
     127// sqlite3 support as of 2.5 has correct table structure built into the CREATE 
     128if($amp_conf["AMPDBENGINE"] != "sqlite3")  { 
     129        $sql = "ALTER TABLE `timeconditions` CHANGE `time` `time` INT (11)"; 
     130        $results = $db->query($sql); 
     131        if(DB::IsError($results)) { 
     132                out(_("ERROR: failed to convert field ").$results->getMessage()); 
     133        } else { 
     134                out(_("OK")); 
     135        } 
    97136} 
    98137 
Donate