phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.schema_proc.inc.php class.sc...


From: Sigurd Nes
Subject: [Phpgroupware-cvs] phpgwapi/inc class.schema_proc.inc.php class.sc...
Date: Mon, 04 Dec 2006 15:04:58 +0000

CVSROOT:        /sources/phpgwapi
Module name:    phpgwapi
Changes by:     Sigurd Nes <sigurdne>   06/12/04 15:04:58

Modified files:
        inc            : class.schema_proc.inc.php 
                         class.schema_proc_mysql.inc.php 

Log message:
        Enable "create index" on update

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/class.schema_proc.inc.php?cvsroot=phpgwapi&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/class.schema_proc_mysql.inc.php?cvsroot=phpgwapi&r1=1.17&r2=1.18

Patches:
Index: class.schema_proc.inc.php
===================================================================
RCS file: /sources/phpgwapi/phpgwapi/inc/class.schema_proc.inc.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- class.schema_proc.inc.php   3 Oct 2006 07:13:52 -0000       1.17
+++ class.schema_proc.inc.php   4 Dec 2006 15:04:58 -0000       1.18
@@ -8,7 +8,7 @@
        * @license http://www.fsf.org/licenses/gpl.html GNU General Public 
License
        * @package phpgwapi
        * @subpackage database
-       * @version $Id: class.schema_proc.inc.php,v 1.17 2006/10/03 07:13:52 
sigurdne Exp $
+       * @version $Id: class.schema_proc.inc.php,v 1.18 2006/12/04 15:04:58 
sigurdne Exp $
        */
 
        /**
@@ -609,5 +609,61 @@
                                 }
                                 return True;
                           }
+               
+               /**
+               * Create Index on tables from tables_update
+               *
+               * @param string|array $aFields fields hold by the index
+               * @param string $sTableName table affected
+               */
+               
+               function CreateIndex($aFields, $sTableName)
+               {
+                       if (count($aFields) < 1 || !$sTableName)
+                       {
+
+                               return false;
+                       }
+
+                       $sIXSQL ='';
+
+                       $num_fields = count($aFields);
+                       $i = 0;
+                       foreach($aFields as $key => $sField)
+                       {
+
+                               if(@is_array($sField))
+                               {
+                                       $sIXSQL .= 
$this->m_oTranslator->GetIXSQL(implode(',', $sField),$sTableName);
+                               }
+                               else
+                               {
+                                       $sIXSQL .= 
$this->m_oTranslator->GetIXSQL($sField,$sTableName);
+
+                               }
+
+                               if($num_fields > 1 && $i < $num_fields-1 && 
$this->dbms == 'mysql')
+                               {
+                                       $sIXSQL .= ', ';
+                               }
+                               ++$i;
+                       }
+                       
+                       if($this->dbms == 'mysql' && $sIXSQL)
+                       {
+                               $this->query($sIXSQL);
+                       }
+                       
+                       // postgres
+                       if(isset($this->m_oTranslator->indexes_sql) && 
is_array($this->m_oTranslator->indexes_sql) && 
count($this->m_oTranslator->indexes_sql)>0)
+                       {
+                               foreach($this->m_oTranslator->indexes_sql as 
$key => $sIndexSQL)
+                               {
+                                       $ix_name = 
str_replace(',','_',$key).'_'.$sTableName.'_idx';
+                                       $IndexSQL = 
str_replace(array('__index_name__','__table_name__'), 
array($ix_name,$sTableName), $sIndexSQL);
+                                       $this->query($IndexSQL);
+                               }
+                       }                       
+               }
        }
 ?>

Index: class.schema_proc_mysql.inc.php
===================================================================
RCS file: /sources/phpgwapi/phpgwapi/inc/class.schema_proc_mysql.inc.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- class.schema_proc_mysql.inc.php     3 Sep 2006 06:15:27 -0000       1.17
+++ class.schema_proc_mysql.inc.php     4 Dec 2006 15:04:58 -0000       1.18
@@ -8,7 +8,7 @@
        * @license http://www.fsf.org/licenses/gpl.html GNU General Public 
License
        * @package phpgwapi
        * @subpackage database
-       * @version $Id: class.schema_proc_mysql.inc.php,v 1.17 2006/09/03 
06:15:27 skwashd Exp $
+       * @version $Id: class.schema_proc_mysql.inc.php,v 1.18 2006/12/04 
15:04:58 sigurdne Exp $
        */
  
        /**
@@ -241,10 +241,17 @@
                        return "UNIQUE($sFields)";
                }
 
-               function GetIXSQL($sFields)
+               function GetIXSQL($sFields, $sTableName = '')
+               {
+                       if($sTableName)
+                       {
+                               return "CREATE INDEX ". 
str_replace(',','_',$sFields) ." USING BTREE ON $sTableName ($sFields)"
+                       }
+                       else
                {
                        return "INDEX ($sFields)";
                }
+               }
 
                           // foreign key supports needs MySQL 3.23.44 and up 
with InnoDB or MySQL 5.1
                           // or other versions the syntax is parsed in table 
create commands




reply via email to

[Prev in Thread] Current Thread [Next in Thread]