tbrehm
2012-05-07 0aa4efbc0b79ba9ab8a66e8facfda8cb16b7c427
commit | author | age
b5a2f8 1 <?php
T 2 /*
d02193 3 Copyright (c) 2007-2012, Till Brehm, projektfarm Gmbh, ISPConfig UG
b5a2f8 4 All rights reserved.
T 5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
436ed8 30 class db {
00dfba 31     private $dbHost = '';           // hostname of the MySQL server
R 32     private $dbName = '';           // logical database name on that server
33     private $dbUser = '';           // database authorized user
34     private $dbPass = '';           // user's password
12fcb2 35     private $dbCharset = '';       // what charset comes and goes to mysql: utf8 / latin1
c84a6d 36     private $dbNewLink = false;    // Return a new linkID when connect is called again
T 37     private $dbClientFlags = 0;    // MySQL Client falgs
00dfba 38     private $linkId = 0;           // last result of mysql_connect()
R 39     private $queryId = 0;           // last result of mysql_query()
40     private $record    = array();       // last record fetched
12fcb2 41     private $autoCommit = 1;        // Autocommit Transactions
00dfba 42     private $currentRow;           // current row number
R 43     private $errorNumber = 0;       // last error number
44     public $errorMessage = '';       // last error message
45     private $errorLocation = '';   // last error location
010876 46     public $show_error_messages = false;
b5a2f8 47
e6c1c4 48     public function __construct()
P 49     {
50         global $conf;
51         $this->dbHost = $conf['db_host'];
52         $this->dbName = $conf['db_database'];
53         $this->dbUser = $conf['db_user'];
54         $this->dbPass = $conf['db_password'];
00dfba 55         $this->dbCharset = $conf['db_charset'];
c84a6d 56         $this->dbNewLink = $conf['db_new_link'];
T 57         $this->dbClientFlags = $conf['db_client_flags'];
e6c1c4 58         //$this->connect();
P 59     }
60
61     /**  Error handler */
62     public function updateError($location)
63     {
64         $this->errorNumber = mysql_errno();
65         $this->errorMessage = mysql_error();
66         $this->errorLocation = $location;
67         if($this->errorNumber && $this->show_error_messages){
68             echo('<br /><b>'.$this->errorLocation.'</b><br />'.$this->errorMessage);
69             flush();
b5a2f8 70         }
e6c1c4 71     }
b5a2f8 72
e6c1c4 73     public function connect()
12fcb2 74     {
e6c1c4 75         if($this->linkId == 0){
c84a6d 76             $this->linkId = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbNewLink, $this->dbClientFlags);
e6c1c4 77             if(!$this->linkId){
P 78                 $this->updateError('DB::connect()<br />mysql_connect');
b5a2f8 79                 return false;
T 80             }
00dfba 81             $this->queryId = @mysql_query('SET NAMES '.$this->dbCharset, $this->linkId);
e65b04 82             $this->queryId = @mysql_query("SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'", $this->linkId);
b5a2f8 83         }
e6c1c4 84         return true;
P 85     }
b5a2f8 86
e6c1c4 87     public function query($queryString)
12fcb2 88     {
e6c1c4 89         if(!$this->connect()){
P 90             return false;
b5a2f8 91         }
e6c1c4 92         if(!mysql_select_db($this->dbName, $this->linkId)){
P 93             $this->updateError('DB::connect()<br />mysql_select_db');
94             return false;
95         }
96         $this->queryId = @mysql_query($queryString, $this->linkId);
97         $this->updateError('DB::query('.$queryString.')<br />mysql_query');
98         if(!$this->queryId){
99             return false;
100         }
101         $this->currentRow = 0;
102         return $this->queryId;
103     }
b5a2f8 104
e6c1c4 105     /** Returns all records as an array */
P 106     public function queryAllRecords($queryString)
12fcb2 107     {
e6c1c4 108         if(!$this->query($queryString)){
P 109             return false;
b5a2f8 110         }
e6c1c4 111         $ret = array();
P 112         while($line = $this->nextRecord()){
113             $ret[] = $line;
114         }
115         return $ret;
116     }
b5a2f8 117
e6c1c4 118     /** Returns one row as an array */
P 119     public function queryOneRecord($queryString)
12fcb2 120     {
e6c1c4 121         if(!$this->query($queryString) || $this->numRows() == 0){
P 122             return false;
b5a2f8 123         }
e6c1c4 124         return $this->nextRecord();
P 125     }
b5a2f8 126
e6c1c4 127     /** Returns the next record as an array */
P 128     public function nextRecord()
12fcb2 129     {
J 130     $this->record = mysql_fetch_assoc($this->queryId);
e6c1c4 131         $this->updateError('DB::nextRecord()<br />mysql_fetch_array');
P 132         if(!$this->record || !is_array($this->record)){
133             return false;
b5a2f8 134         }
e6c1c4 135         $this->currentRow++;
P 136         return $this->record;
137     }
138
139     /** Returns the number of rows returned by the last select query */
140     public function numRows()
141     {
142         return mysql_num_rows($this->queryId);
143     }
144
145     public function affectedRows()
146     {
147         return mysql_affected_rows($this->linkId);
148     }
b5a2f8 149         
e6c1c4 150     /** Returns the last mySQL insert_id() */
P 151     public function insertID()
12fcb2 152     {
e6c1c4 153         return mysql_insert_id($this->linkId);
P 154     }
b5a2f8 155         
e6c1c4 156     /** Checks a variable - Depreciated, use quote() */
P 157     public function check($formfield)
158     {
159         return $this->quote($formfield);
160     }
b5a2f8 161         
8500be 162     /** Escapes quotes in variable. mysql_real_escape_string() */
e6c1c4 163     public function quote($formfield)
8500be 164     {    
T 165         if(!$this->connect()){
166             $this->updateError('WARNING: mysql_connect: Used addslashes instead of mysql_real_escape_string');
167             return addslashes($formfield);
168         }
169         return mysql_real_escape_string($formfield, $this->linkId);
e6c1c4 170     }
b5a2f8 171         
e6c1c4 172     /** Unquotes a variable, strip_slashes() */
P 173     public function unquote($formfield)
174     {
175         return stripslashes($formfield);
176     }
b5a2f8 177         
e6c1c4 178     public function toLower($record)
P 179     {
180         if(is_array($record)){
181             foreach($record as $key => $val) {
182                 $key = strtolower($key);
183                 $out[$key] = $val;
b5a2f8 184             }
T 185         }
e6c1c4 186         return $out;
P 187     }
b5a2f8 188        
430a0f 189     // deprecated
T 190     /*
e6c1c4 191     public function insert($tablename, $form, $debug = 0)
P 192     {
193         if(is_array($form)){
194             foreach($form as $key => $value){
195                 $sql_key .= "$key, ";
196                 $sql_value .= "'".$this->check($value)."', ";
197             }
198             $sql_key = substr($sql_key,0,strlen($sql_key) - 2);
199             $sql_value = substr($sql_value,0,strlen($sql_value) - 2);
200             $sql = "INSERT INTO $tablename (".$sql_key.') VALUES ('.$sql_value.')';
201             //TODO: where has $debug come from !???
202             if($debug == 1){ echo "SQL-Statement: $sql<br><br>"; }
203             $this->query($sql);
204             if($debug == 1){ echo 'mySQL Error Message: '.$this->errorMessage; }
205         }
206     }
430a0f 207     
T 208     // Deprecated
e6c1c4 209     public function update($tablename, $form, $bedingung, $debug = 0)
P 210     {
211         if(is_array($form)){
212             foreach($form as $key => $value){
213                 $insql .= "$key = '".$this->check($value)."', ";
214             }
215             $insql = substr($insql, 0, strlen($insql) - 2);
216             $sql = "UPDATE $tablename SET " . $insql . " WHERE $bedingung";
217             if($debug == 1){ echo "SQL-Statement: $sql<br><br>"; }
218             $this->query($sql);
219             if($debug == 1){ echo 'mySQL Error Message: '.$this->errorMessage; }
220         }
221     }
430a0f 222     */
12fcb2 223
74829e 224     public function diffrec($record_old, $record_new) {
958705 225         $diffrec_full = array();
T 226         $diff_num = 0;
227
228         if(is_array($record_old) && count($record_old) > 0) {
229             foreach($record_old as $key => $val) {
74829e 230                 // if(!isset($record_new[$key]) || $record_new[$key] != $val) {
T 231                 if($record_new[$key] != $val) {
958705 232                     // Record has changed
T 233                     $diffrec_full['old'][$key] = $val;
234                     $diffrec_full['new'][$key] = $record_new[$key];
235                     $diff_num++;
236                 } else {
237                     $diffrec_full['old'][$key] = $val;
238                     $diffrec_full['new'][$key] = $val;
239                 }
240             }
241         } elseif(is_array($record_new)) {
242             foreach($record_new as $key => $val) {
8065e0 243                 if(isset($record_new[$key]) && @$record_old[$key] != $val) {
958705 244                     // Record has changed
T 245                     $diffrec_full['new'][$key] = $val;
8065e0 246                     $diffrec_full['old'][$key] = @$record_old[$key];
958705 247                     $diff_num++;
T 248                 } else {
249                     $diffrec_full['new'][$key] = $val;
250                     $diffrec_full['old'][$key] = $val;
251                 }
252             }
253         }
254         
74829e 255         return array('diff_num' => $diff_num, 'diff_rec' => $diffrec_full);
T 256         
257     }
258     
259     //** Function to fill the datalog with a full differential record.
d02193 260     public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) {
74829e 261         global $app,$conf;
T 262
d02193 263         //* Insert backticks only for incomplete table names.
74829e 264         if(stristr($db_table,'.')) {
T 265             $escape = '';
266         } else {
267             $escape = '`';
268         }
269         
d02193 270         if($force_update == true) {
T 271             //* We force a update even if no record has changed
272             $diffrec_full = array('new' => $record_new, 'old' => $record_old);
273             $diff_num = count($record_new);
274         } else {
275             //* get the difference record between old and new record
276             $tmp = $this->diffrec($record_old, $record_new);
277             $diffrec_full = $tmp['diff_rec'];
278             $diff_num = $tmp['diff_num'];
279             unset($tmp);
280         }
281         
282         //* Insert the server_id, if the record has a server_id
12fcb2 283         $server_id = (isset($record_old['server_id']) && $record_old['server_id'] > 0)?$record_old['server_id']:0;
J 284         if(isset($record_new['server_id'])) $server_id = $record_new['server_id'];
430a0f 285         
958705 286
T 287         if($diff_num > 0) {
288             $diffstr = $app->db->quote(serialize($diffrec_full));
12fcb2 289             $username = $app->db->quote($_SESSION['s']['user']['username']);
J 290             $dbidx = $primary_field.':'.$primary_id;
958705 291                         
T 292             if($action == 'INSERT') $action = 'i';
293             if($action == 'UPDATE') $action = 'u';
294             if($action == 'DELETE') $action = 'd';
295             $sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$db_table."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')";
296             $app->db->query($sql);
297         }
298
299         return true;
300     }
301     
eea5cf 302     //** Inserts a record and saves the changes into the datalog
430a0f 303     public function datalogInsert($tablename, $insert_data, $index_field) {
T 304         global $app;
305         
471560 306         if(is_array($insert_data)) {
T 307             $key_str = '';
308             $val_str = '';
309             foreach($insert_data as $key => $val) {
310                 $key_str .= "`".$key ."`,";
311                 $val_str .= "'".$this->quote($val)."',";
312             }
0aa4ef 313             $key_str = substr($key_str,0,-1);
T 314             $val_str = substr($val_str,0,-1);
471560 315             $insert_data_str = '('.$key_str.') VALUES ('.$val_str.')';
T 316         } else {
317             $insert_data_str = $insert_data;
318         }
319         
430a0f 320         $old_rec = array();
471560 321         $this->query("INSERT INTO $tablename $insert_data_str");
430a0f 322         $index_value = $this->insertID();
T 323         $new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
324         $this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
325         
13d323 326         return $index_value;
430a0f 327     }
T 328     
329     //** Updates a record and saves the changes into the datalog
fddedd 330     public function datalogUpdate($tablename, $update_data, $index_field, $index_value, $force_update = false) {
958705 331         global $app;
T 332         
d02193 333         $old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
471560 334         
T 335         if(is_array($update_data)) {
336             $update_data_str = '';
337             foreach($update_data as $key => $val) {
338                 $update_data_str .= "`".$key ."` = '".$this->quote($val)."',";
339             }
0aa4ef 340             $update_data_str = substr($update_data_str,0,-1);
471560 341         } else {
T 342             $update_data_str = $update_data;
343         }
344         
345         $this->query("UPDATE $tablename SET $update_data_str WHERE $index_field = '$index_value'");
958705 346         $new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
d02193 347         $this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec, $force_update);
958705 348         
T 349         return true;
350     }
430a0f 351     
T 352     //** Deletes a record and saves the changes into the datalog
353     public function datalogDelete($tablename, $index_field, $index_value) {
354         global $app;
355         
356         $old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
357         $this->query("DELETE FROM $tablename WHERE $index_field = '$index_value'");
358         $new_rec = array();
359         $this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec);
360         
361         return true;
362     }
12fcb2 363
J 364
b5a2f8 365        
e6c1c4 366     public function closeConn()
P 367     {
55da90 368         if($this->linkId)
B 369         {
370             mysql_close($this->linkId);
371             return true;
372         } else { return false; }
e6c1c4 373     }
12fcb2 374     
55da90 375     public function freeResult($query) 
e6c1c4 376     {
55da90 377         if(mysql_free_result($query))
B 378         {
379             return true;
380         } else {
381             return false;
382         }
e6c1c4 383     }
430a0f 384     
T 385     /*
e6c1c4 386     public function delete()
P 387     {
388     }
430a0f 389     */
T 390     
391     /*
e6c1c4 392     public function Transaction($action)
P 393     {
394         //action = begin, commit oder rollback
395     }
430a0f 396     */
e6c1c4 397     
P 398     /** Creates a database table with the following format for the $columns array   
399     * <code>
400     * $columns = array(action =>   add | alter | drop
401     *                  name =>     Spaltenname
402     *                  name_new => neuer Spaltenname, nur bei 'alter' belegt
403     *                  type =>     42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob
404     *                  typeValue => Wert z.B. bei Varchar
405     *                  defaultValue =>  Default Wert
406     *                  notNull =>   true | false
407     *                  autoInc =>   true | false
408     *                  option =>   unique | primary | index)
409     * </code>   
410     */
430a0f 411     
T 412     
e6c1c4 413     public function createTable($table_name, $columns)
P 414     {
415         $index = '';
416         $sql = "CREATE TABLE $table_name (";
417         foreach($columns as $col){
418             $sql .= $col['name'].' '.$this->mapType($col['type'], $col['typeValue']).' ';
419             //* Set default value
010876 420             if(isset($col['defaultValue']) && $col['defaultValue'] != '') {
e6c1c4 421                 if($col['defaultValue'] == 'NULL' or $col['defaultValue'] == 'NOT NULL') {
P 422                     $sql .= 'DEFAULT '.$col['defaultValue'].' ';
423                 } else {
424                     $sql .= "DEFAULT '".$col['defaultValue']."' ";
425                 }
426             } elseif($col['defaultValue'] != false) {
427                 $sql .= "DEFAULT '' ";
428             }
010876 429             if(isset($col['defaultValue']) && $col['defaultValue'] != 'NULL' && $col['defaultValue'] != 'NOT NULL') {
e6c1c4 430                 if($col['notNull'] == true) {
P 431                     $sql .= 'NOT NULL ';
432                 } else {
433                     $sql .= 'NULL ';
434                 }
435             }
010876 436             if(isset($col['autoInc']) && $col['autoInc'] == true){ $sql .= 'auto_increment '; }
e6c1c4 437             $sql.= ',';
P 438             //* Index Definitions
010876 439             if(isset($col['option']) && $col['option'] == 'primary'){ $index .= 'PRIMARY KEY ('.$col['name'].'),'; }
T 440             if(isset($col['option']) && $col['option'] == 'index'){   $index .= 'INDEX ('.$col['name'].'),'; }
441             if(isset($col['option']) && $col['option'] == 'unique'){  $index .= 'UNIQUE ('.$col['name'].'),'; }
12fcb2 442        }
b5a2f8 443        $sql .= $index;
T 444        $sql = substr($sql,0,-1);
12fcb2 445        $sql .= ')';
b5a2f8 446        $this->query($sql);
T 447        return true;
e6c1c4 448     }
b5a2f8 449        
e6c1c4 450     /** Changes a table definition. The format for the $columns array is 
P 451     * <code>
452     * $columns = array(action =>   add | alter | drop
453     *                  name =>     Spaltenname
454     *                 name_new => neuer Spaltenname, nur bei 'alter' belegt
455     *                 type =>     42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob
456     *                 typeValue => Wert z.B. bei Varchar
457     *                 defaultValue =>  Default Wert
458     *                 notNull =>   true | false
459     *                 autoInc =>   true | false
460     *                 option =>   unique | primary | index)
461     */
462     public function alterTable($table_name,$columns)
463     {
12fcb2 464        $index = '';
J 465        $sql = "ALTER TABLE $table_name ";
466        foreach($columns as $col){
e6c1c4 467             if($col['action'] == 'add'){
12fcb2 468                 $sql .= 'ADD '.$col['name'].' '.$this->mapType($col['type'],$col['typeValue']).' ';
e6c1c4 469             }elseif($col['action'] == 'alter') {
P 470                 $sql .= 'CHANGE '.$col['name'].' '.$col['name_new'].' '.$this->mapType($col['type'],$col['typeValue']).' ';
471             }elseif($col['action'] == 'drop') {
472                 $sql .= 'DROP '.$col['name'].' ';
b5a2f8 473             }
12fcb2 474             if($col['action'] != 'drop') {  
J 475             if($col['defaultValue'] != '') $sql .= "DEFAULT '".$col['defaultValue']."' ";
476             if($col['notNull'] == true) {
477                 $sql .= 'NOT NULL ';
b5a2f8 478             } else {
12fcb2 479                 $sql .= 'NULL ';
b5a2f8 480             }
12fcb2 481             if($col['autoInc'] == true) $sql .= 'auto_increment ';
J 482             $sql.= ',';
e6c1c4 483             //* Index definitions
P 484             if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),';
485             if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),';
486             if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),';
b5a2f8 487             }
12fcb2 488        }
J 489        $sql .= $index;
490        $sql = substr($sql,0,-1);
491        //die($sql);
492        $this->query($sql);
493        return true;
e6c1c4 494     }
b5a2f8 495        
e6c1c4 496     public function dropTable($table_name) 
P 497     {
498         $this->check($table_name);
499         $sql = "DROP TABLE '". $table_name."'";
500         return $this->query($sql);
501     }
b5a2f8 502        
e6c1c4 503     /** Return an array of table names */
P 504     public function getTables($database_name = '')
505     {
506         if($database_name == ''){
507             $database_name = $this->dbName;
508         }
92bc67 509         $result = @mysql_list_tables($database_name);
e6c1c4 510         $tb_names = array();
92bc67 511         for ($i = 0; $i < @mysql_num_rows($result); $i++) {
T 512             $tb_names[$i] = @mysql_tablename($result, $i);
e6c1c4 513         }
P 514         return $tb_names;       
515     }
b5a2f8 516        
T 517        
e6c1c4 518     public function tableInfo($table_name) {
P 519         //* Tabellenfelder einlesen ?
fb3a98 520         if($rows = $this->queryAllRecords('SHOW FIELDS FROM '.$table_name)){
b5a2f8 521         foreach($rows as $row) {
07ba80 522             $name    = $row['Field'];
T 523             $default = $row['Default'];
524             $key     = $row['Key'];
525             $extra   = $row['Extra'];
526             $isnull  = $row['Null'];
527             $type    = $row['Type'];
b5a2f8 528         
e6c1c4 529             $column = array('name' => $name, 'defaultValue' => $default);
b5a2f8 530             //$column["type"] = $type;
e6c1c4 531             if(stristr($key, 'PRI')){ $column['option'] = 'primary'; }
P 532             $column['notNull'] = stristr($isnull,'YES') ? false : true;
533             if($extra == 'auto_increment'){ $column['autoInc'] = true; }         
b5a2f8 534             
e6c1c4 535             //* Get the Data and Metatype
P 536             if( stristr($type, 'int(') ){    $metaType = 'int32'; }
537             if( stristr($type, 'bigint') ){  $metaType = 'int64'; }
538             if( stristr($type, 'char') ) {
b5a2f8 539                 $metaType = 'char';
T 540                 $tmp_typeValue = explode('(',$type);
e6c1c4 541                 $column['typeValue'] = substr($tmp_typeValue[1], 0, -1);  
b5a2f8 542             }
e6c1c4 543             if( stristr($type, 'varchar') ){
b5a2f8 544                 $metaType = 'varchar';
T 545                 $tmp_typeValue = explode('(',$type);
e6c1c4 546                 $column['typeValue'] = substr($tmp_typeValue[1], 0, -1);  
b5a2f8 547             }
12fcb2 548             if(stristr($type,'text'))   $metaType = 'text';
J 549             if(stristr($type,'double')) $metaType = 'double';
550             if(stristr($type,'blob'))   $metaType = 'blob';
b5a2f8 551             
e6c1c4 552             $column['type'] = $metaType;
P 553             $columns[] = $column;
b5a2f8 554         }
T 555             return $columns;
556         } else {
557             return false;
558         }
e6c1c4 559     }
b5a2f8 560        
e6c1c4 561     public function mapType($metaType, $typeValue) {
P 562         //TODO: ? this is not required ?? global $go_api;
563         $metaType = strtolower($metaType);
564         switch ($metaType) {
565         case 'int16':
b5a2f8 566             return 'smallint';
e6c1c4 567         case 'int32':
b5a2f8 568             return 'int';
e6c1c4 569         case 'int64':
b5a2f8 570             return 'bigint';
e6c1c4 571         case 'double':
b5a2f8 572             return 'double';
e6c1c4 573         case 'char':
b5a2f8 574             return 'char';
e6c1c4 575         case 'varchar':
P 576             if($typeValue < 1) die('Datenbank Fehler: F�r diesen Datentyp ist eine L�ngenangabe notwendig.');
b5a2f8 577             return 'varchar('.$typeValue.')';
e6c1c4 578         case 'text':
b5a2f8 579             return 'text';
e6c1c4 580         case 'blob':
b5a2f8 581             return 'blob';
e6c1c4 582         }
P 583     }
12fcb2 584
e6c1c4 585 }
b5a2f8 586
12fcb2 587 ?>