Changeset 639
- Timestamp:
- 11/13/07 01:38:24 (1 year ago)
- Files:
-
- trunk/build/manifests/testapp.mn (modified) (2 diffs)
- trunk/build/manifests/testapp.mn (modified) (2 diffs)
- trunk/lib/jelix-scripts/commands/createdao.cmd.php (modified) (3 diffs)
- trunk/lib/jelix-scripts/commands/createdao.cmd.php (modified) (3 diffs)
- trunk/lib/jelix/dao/jDaoParser.class.php (modified) (2 diffs)
- trunk/lib/jelix/dao/jDaoParser.class.php (modified) (2 diffs)
- trunk/lib/jelix/db/jDb.class.php (modified) (1 diff)
- trunk/lib/jelix/db/jDb.class.php (modified) (1 diff)
- trunk/lib/jelix/db/jDbTools.class.php (modified) (1 diff)
- trunk/lib/jelix/db/jDbTools.class.php (modified) (1 diff)
- trunk/lib/jelix/plugins/db/mysql/mysql.dbtools.php (modified) (1 diff)
- trunk/lib/jelix/plugins/db/mysql/mysql.dbtools.php (modified) (1 diff)
- trunk/lib/jelix/plugins/db/pgsql/pgsql.dbtools.php (modified) (3 diffs)
- trunk/lib/jelix/plugins/db/pgsql/pgsql.dbtools.php (modified) (3 diffs)
- trunk/lib/jelix/plugins/db/sqlite/sqlite.dbtools.php (modified) (1 diff)
- trunk/lib/jelix/plugins/db/sqlite/sqlite.dbtools.php (modified) (1 diff)
- trunk/testapp/install/install.mysql.sql (modified) (1 diff)
- trunk/testapp/install/install.mysql.sql (modified) (1 diff)
- trunk/testapp/install/install.pgsql.sql (added)
- trunk/testapp/install/install.pgsql.sql (added)
- trunk/testapp/modules/jelix_tests/tests/jdao.parser_update.html.php (modified) (2 diffs)
- trunk/testapp/modules/jelix_tests/tests/jdao.parser_update.html.php (modified) (2 diffs)
- trunk/testapp/modules/jelix_tests/tests/jdb.1_queries.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jdb.1_queries.html.php (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jdb.pgsql.html.php (added)
- trunk/testapp/modules/jelix_tests/tests/jdb.pgsql.html.php (added)
- trunk/testapp/var/config/dbprofils.ini.php.dist (modified) (1 diff)
- trunk/testapp/var/config/dbprofils.ini.php.dist (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/testapp.mn
r638 r639 26 26 cd testapp/install 27 27 install.mysql.sql 28 install.pgsql.sql 28 29 29 30 cd testapp/modules/testapp … … 120 121 jdb.1_queries.html.php 121 122 jdb.2_queries_with_pdo.html.php 123 jdb.pgsql.html.php 122 124 jforms.html.php 123 125 jforms.check_datas.html.php trunk/build/manifests/testapp.mn
r638 r639 26 26 cd testapp/install 27 27 install.mysql.sql 28 install.pgsql.sql 28 29 29 30 cd testapp/modules/testapp … … 120 121 jdb.1_queries.html.php 121 122 jdb.2_queries_with_pdo.html.php 123 jdb.pgsql.html.php 122 124 jforms.html.php 123 125 jforms.check_datas.html.php trunk/lib/jelix-scripts/commands/createdao.cmd.php
r576 r639 92 92 case 'smallint': 93 93 case 'year': 94 if($prop->auto _increment ){94 if($prop->autoIncrement ){ 95 95 $type='autoincrement'; 96 96 }else{ … … 101 101 case 'mediumint': 102 102 case 'bigint': 103 if($prop->auto _increment ){103 if($prop->autoIncrement ){ 104 104 $type='bigautoincrement'; 105 105 }else{ … … 136 136 $primarykeys.=$fieldname; 137 137 } 138 if($prop->not _null && !$prop->auto_increment)138 if($prop->notNull && !$prop->auto_increment) 139 139 $properties.=' required="true"'; 140 140 $properties.='/>'; trunk/lib/jelix-scripts/commands/createdao.cmd.php
r576 r639 92 92 case 'smallint': 93 93 case 'year': 94 if($prop->auto _increment ){94 if($prop->autoIncrement ){ 95 95 $type='autoincrement'; 96 96 }else{ … … 101 101 case 'mediumint': 102 102 case 'bigint': 103 if($prop->auto _increment ){103 if($prop->autoIncrement ){ 104 104 $type='bigautoincrement'; 105 105 }else{ … … 136 136 $primarykeys.=$fieldname; 137 137 } 138 if($prop->not _null && !$prop->auto_increment)138 if($prop->notNull && !$prop->auto_increment) 139 139 $properties.=' required="true"'; 140 140 $properties.='/>'; trunk/lib/jelix/dao/jDaoParser.class.php
r638 r639 396 396 $this->_def = $def; 397 397 398 $params = $def->getAttr($method, array('name', 'type', 'call','distinct', 'event Before', 'eventAfter'));398 $params = $def->getAttr($method, array('name', 'type', 'call','distinct', 'eventbefore', 'eventafter')); 399 399 400 400 if ($params['name']===null){ … … 441 441 442 442 if ($this->type == 'update' || $this->type == 'delete') { 443 if ($params['event Before'] == 'true')443 if ($params['eventbefore'] == 'true') 444 444 $this->eventBeforeEnabled = true; 445 if ($params['event After'] == 'true')445 if ($params['eventafter'] == 'true') 446 446 $this->eventAfterEnabled = true; 447 447 } trunk/lib/jelix/dao/jDaoParser.class.php
r638 r639 396 396 $this->_def = $def; 397 397 398 $params = $def->getAttr($method, array('name', 'type', 'call','distinct', 'event Before', 'eventAfter'));398 $params = $def->getAttr($method, array('name', 'type', 'call','distinct', 'eventbefore', 'eventafter')); 399 399 400 400 if ($params['name']===null){ … … 441 441 442 442 if ($this->type == 'update' || $this->type == 'delete') { 443 if ($params['event Before'] == 'true')443 if ($params['eventbefore'] == 'true') 444 444 $this->eventBeforeEnabled = true; 445 if ($params['event After'] == 'true')445 if ($params['eventafter'] == 'true') 446 446 $this->eventAfterEnabled = true; 447 447 } trunk/lib/jelix/db/jDb.class.php
r582 r639 90 90 global $gJConfig; 91 91 #ifnot ENABLE_OPTIMIZED_SOURCE 92 if(!isset($gJConfig->_pluginsPathList_db[$ profil['driver']])93 || !file_exists($gJConfig->_pluginsPathList_db[$ profil['driver']]) ){94 throw new jException('jelix~db.error.driver.notfound', $ profil['driver']);92 if(!isset($gJConfig->_pluginsPathList_db[$driver]) 93 || !file_exists($gJConfig->_pluginsPathList_db[$driver]) ){ 94 throw new jException('jelix~db.error.driver.notfound', $driver); 95 95 } 96 96 #endif 97 require_once($gJConfig->_pluginsPathList_db[$ profil['driver']].$profil['driver'].'.dbtools.php');98 $class = $ profil['driver'].'DbTools';97 require_once($gJConfig->_pluginsPathList_db[$driver].$driver.'.dbtools.php'); 98 $class = $driver.'DbTools'; 99 99 100 100 //Création de l'objet trunk/lib/jelix/db/jDb.class.php
r582 r639 90 90 global $gJConfig; 91 91 #ifnot ENABLE_OPTIMIZED_SOURCE 92 if(!isset($gJConfig->_pluginsPathList_db[$ profil['driver']])93 || !file_exists($gJConfig->_pluginsPathList_db[$ profil['driver']]) ){94 throw new jException('jelix~db.error.driver.notfound', $ profil['driver']);92 if(!isset($gJConfig->_pluginsPathList_db[$driver]) 93 || !file_exists($gJConfig->_pluginsPathList_db[$driver]) ){ 94 throw new jException('jelix~db.error.driver.notfound', $driver); 95 95 } 96 96 #endif 97 require_once($gJConfig->_pluginsPathList_db[$ profil['driver']].$profil['driver'].'.dbtools.php');98 $class = $ profil['driver'].'DbTools';97 require_once($gJConfig->_pluginsPathList_db[$driver].$driver.'.dbtools.php'); 98 $class = $driver.'DbTools'; 99 99 100 100 //Création de l'objet trunk/lib/jelix/db/jDbTools.class.php
r582 r639 22 22 */ 23 23 class jDbFieldProperties { 24 /** 25 * type of the field 26 * @var string 27 */ 24 28 public $type; 29 30 /** 31 * field name 32 * @var string 33 */ 25 34 public $name; 26 public $not_null=true; 35 36 /** 37 * says if the field can be null or not 38 * @var boolean 39 */ 40 public $notNull=true; 41 42 /** 43 * says if the field is the primary key 44 * @var boolean 45 */ 27 46 public $primary=false; 28 public $auto_increment=false; 47 48 /** 49 * says if the field is auto incremented 50 * @var boolean 51 */ 52 public $autoIncrement=false; 53 54 /** 55 * default value 56 * @var string 57 */ 58 public $default=''; 59 60 /** 61 * says if there is a default value 62 * @var boolean 63 */ 64 public $hasDefault = false; 65 66 67 public $length = 0; 29 68 } 30 69 trunk/lib/jelix/db/jDbTools.class.php
r582 r639 22 22 */ 23 23 class jDbFieldProperties { 24 /** 25 * type of the field 26 * @var string 27 */ 24 28 public $type; 29 30 /** 31 * field name 32 * @var string 33 */ 25 34 public $name; 26 public $not_null=true; 35 36 /** 37 * says if the field can be null or not 38 * @var boolean 39 */ 40 public $notNull=true; 41 42 /** 43 * says if the field is the primary key 44 * @var boolean 45 */ 27 46 public $primary=false; 28 public $auto_increment=false; 47 48 /** 49 * says if the field is auto incremented 50 * @var boolean 51 */ 52 public $autoIncrement=false; 53 54 /** 55 * default value 56 * @var string 57 */ 58 public $default=''; 59 60 /** 61 * says if there is a default value 62 * @var boolean 63 */ 64 public $hasDefault = false; 65 66 67 public $length = 0; 29 68 } 30 69 trunk/lib/jelix/plugins/db/mysql/mysql.dbtools.php
r582 r639 22 22 class mysqlDbTools extends jDbTools { 23 23 24 /** 25 * retourne la liste des tables 26 * @return array $tab[] = $nomDeTable 27 */ 28 function _getTableList (){ 29 $results = array (); 24 /** 25 * retourne la liste des tables 26 * @return array $tab[] = $nomDeTable 27 */ 28 function _getTableList (){ 29 $results = array (); 30 31 $rs = $this->_connector->query ('SHOW TABLES FROM '.$this->_connector->profil['database']); 32 $col_name = 'Tables_in_'.$this->_connector->profil['database']; 33 34 while ($line = $rs->fetch ()){ 35 $results[] = $line->$col_name; 36 } 37 38 return $results; 39 } 30 40 31 $rs = $this->_connector->query ('SHOW TABLES FROM '.$this->_connector->profil['database']); 32 $col_name = 'Tables_in_'.$this->_connector->profil['database']; 33 34 while ($line = $rs->fetch ()){ 35 $results[] = $line->$col_name; 36 } 37 38 return $results; 39 } 40 41 /** 42 * récupère la liste des champs pour une base donnée. 43 * @return array $tab[NomDuChamp] = obj avec prop (tye, length, lengthVar, notnull) 44 */ 45 function _getFieldList ($tableName){ 46 $results = array (); 47 48 $rs = $this->_connector->query ('SHOW FIELDS FROM ' . $tableName); 49 50 while ($result_line = $rs->fetch ()){ 51 $field = new jDbFieldProperties(); 52 53 $type = $result_line->Type; 54 55 /** 56 * récupéré depuis phpMyAdmin 57 */ 58 // set or enum types: slashes single quotes inside options 59 $type = str_replace('BINARY', '', $type); 60 $type = str_replace('ZEROFILL', '', $type); 61 $type = str_replace('UNSIGNED', '', $type); 62 /* 63 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)){ 64 $type = $tmp[1]; 65 $length = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1); 66 }else{ 67 $length = $type; 68 $type = chop(eregi_replace('\\(.*\\)', '', $type)); 69 if (!empty($type)){ 70 $length = eregi_replace("^$type\(", '', $length); 71 $length = eregi_replace('\)$', '', trim($length)); 72 } 73 if ($length == $type){ 74 $length = ''; 75 } 76 }*/ 77 78 preg_match('/^(\w+).*$/',$type,$m); 79 80 81 $field->type = $m[1]; 82 $field->name = $result_line->Field; 83 //$p_result_line->length = $length; 84 $field->not_null = (trim ($result_line->Null) != 'YES'); 85 $field->primary = (trim ($result_line->Key) == 'PRI'); 86 $field->auto_increment = ($result_line->Extra == 'auto_increment'); 87 $results[$result_line->Field] = $field; 88 } 89 return $results; 90 } 41 /** 42 * récupère la liste des champs pour une base donnée. 43 * @return array $tab[NomDuChamp] = obj avec prop (tye, length, lengthVar, notnull) 44 */ 45 function _getFieldList ($tableName){ 46 $results = array (); 47 48 $rs = $this->_connector->query ('SHOW FIELDS FROM ' . $tableName); 49 50 while ($line = $rs->fetch ()){ 51 $field = new jDbFieldProperties(); 52 preg_match('/^(\w+).*$/',$line->Type,$m); 53 $field->type = $m[1]; 54 $field->name = $line->Field; 55 $field->notNull = ($line->Null == 'NO'); 56 $field->primary = ($line->Key == 'PRI'); 57 $field->hasDefault = ($line->Default != '' || !($line->Default == null && $field->notNull)); 58 $field->default = $line->Default; 59 $field->autoIncrement = ($line->Extra == 'auto_increment'); 60 $results[$line->Field] = $field; 61 } 62 return $results; 63 } 91 64 } 92 65 ?> trunk/lib/jelix/plugins/db/mysql/mysql.dbtools.php
r582 r639 22 22 class mysqlDbTools extends jDbTools { 23 23 24 /** 25 * retourne la liste des tables 26 * @return array $tab[] = $nomDeTable 27 */ 28 function _getTableList (){ 29 $results = array (); 24 /** 25 * retourne la liste des tables 26 * @return array $tab[] = $nomDeTable 27 */ 28 function _getTableList (){ 29 $results = array (); 30 31 $rs = $this->_connector->query ('SHOW TABLES FROM '.$this->_connector->profil['database']); 32 $col_name = 'Tables_in_'.$this->_connector->profil['database']; 33 34 while ($line = $rs->fetch ()){ 35 $results[] = $line->$col_name; 36 } 37 38 return $results; 39 } 30 40 31 $rs = $this->_connector->query ('SHOW TABLES FROM '.$this->_connector->profil['database']); 32 $col_name = 'Tables_in_'.$this->_connector->profil['database']; 33 34 while ($line = $rs->fetch ()){ 35 $results[] = $line->$col_name; 36 } 37 38 return $results; 39 } 40 41 /** 42 * récupère la liste des champs pour une base donnée. 43 * @return array $tab[NomDuChamp] = obj avec prop (tye, length, lengthVar, notnull) 44 */ 45 function _getFieldList ($tableName){ 46 $results = array (); 47 48 $rs = $this->_connector->query ('SHOW FIELDS FROM ' . $tableName); 49 50 while ($result_line = $rs->fetch ()){ 51 $field = new jDbFieldProperties(); 52 53 $type = $result_line->Type; 54 55 /** 56 * récupéré depuis phpMyAdmin 57 */ 58 // set or enum types: slashes single quotes inside options 59 $type = str_replace('BINARY', '', $type); 60 $type = str_replace('ZEROFILL', '', $type); 61 $type = str_replace('UNSIGNED', '', $type); 62 /* 63 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)){ 64 $type = $tmp[1]; 65 $length = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1); 66 }else{ 67 $length = $type; 68 $type = chop(eregi_replace('\\(.*\\)', '', $type)); 69 if (!empty($type)){ 70 $length = eregi_replace("^$type\(", '', $length); 71 $length = eregi_replace('\)$', '', trim($length)); 72 } 73 if ($length == $type){ 74 $length = ''; 75 } 76 }*/ 77 78 preg_match('/^(\w+).*$/',$type,$m); 79 80 81 $field->type = $m[1]; 82 $field->name = $result_line->Field; 83 //$p_result_line->length = $length; 84 $field->not_null = (trim ($result_line->Null) != 'YES'); 85 $field->primary = (trim ($result_line->Key) == 'PRI'); 86 $field->auto_increment = ($result_line->Extra == 'auto_increment'); 87 $results[$result_line->Field] = $field; 88 } 89 return $results; 90 } 41 /** 42 * récupère la liste des champs pour une base donnée. 43 * @return array $tab[NomDuChamp] = obj avec prop (tye, length, lengthVar, notnull) 44 */ 45 function _getFieldList ($tableName){ 46 $results = array (); 47 48 $rs = $this->_connector->query ('SHOW FIELDS FROM ' . $tableName); 49 50 while ($line = $rs->fetch ()){ 51 $field = new jDbFieldProperties(); 52 preg_match('/^(\w+).*$/',$line->Type,$m); 53 $field->type = $m[1]; 54 $field->name = $line->Field; 55 $field->notNull = ($line->Null == 'NO'); 56 $field->primary = ($line->Key == 'PRI'); 57 $field->hasDefault = ($line->Default != '' || !($line->Default == null && $field->notNull)); 58 $field->default = $line->Default; 59 $field->autoIncrement = ($line->Extra == 'auto_increment'); 60 $results[$line->Field] = $field; 61 } 62 return $results; 63 } 91 64 } 92 65 ?> trunk/lib/jelix/plugins/db/pgsql/pgsql.dbtools.php
r631 r639 3 3 * @package jelix 4 4 * @subpackage db_driver 5 * @author Croes Gérald, Ferlet Patrice,Laurent Jouanneau5 * @author Laurent Jouanneau 6 6 * @contributor Laurent Jouanneau 7 7 * @contributor Nicolas Jeudy (patch ticket #99) 8 * @copyright 2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 9 * This class was get originally from the Copix project (CopixDBToolsPostgreSQL, Copix 2.3dev20050901, http://www.copix.org) 10 * Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). 11 * Initial authors of this Copix class are Gerald Croes, Ferlet Patrice and Laurent Jouanneau, 12 * and this class was adapted for Jelix by Laurent Jouanneau 13 * 8 * @copyright 2005-2007 Laurent Jouanneau 14 9 * @link http://www.jelix.org 15 10 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file … … 29 24 protected function _getTableList (){ 30 25 $results = array (); 31 $sql = "SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%'ORDER BY tablename";26 $sql = "SELECT tablename FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema') ORDER BY tablename"; 32 27 $rs = $this->_connector->query ($sql); 33 28 while ($line = $rs->fetch()){ … … 42 37 protected function _getFieldList ($tableName){ 43 38 $results = array (); 44 $sql_get_fields = "SELECT 45 a.attname as Field, t.typname as type, a.attlen as length, a.atttypmod, 46 case when a.attnotnull then 1 else 0 end as notnull, 47 a.atthasdef, 48 (SELECT adsrc FROM pg_attrdef adef WHERE a.attrelid=adef.adrelid AND a.attnum=adef.adnum) AS adsrc 49 FROM 50 pg_attribute a, 51 pg_class c, 52 pg_type t 39 40 // get table informations 41 $sql ='SELECT oid, relhaspkey, relhasindex FROM pg_class WHERE relname = \''.$tableName.'\''; 42 $rs = $this->_connector->query ($sql); 43 if (! ($table = $rs->fetch())) { 44 throw new Exception('dbtools, pgsql: unknow table'); 45 } 46 47 $pkeys = array(); 48 // get primary keys informations 49 if ($table->relhaspkey == 't') { 50 $sql = 'SELECT indkey FROM pg_index WHERE indrelid = '.$table->oid.' and indisprimary = true'; 51 $rs = $this->_connector->query ($sql); 52 $pkeys = preg_split("/[\s]+/", $rs->fetch()->indkey); 53 } 54 55 // get field informations 56 $sql_get_fields = "SELECT t.typname, a.attname, a.attnotnull, a.attnum, 57 a.atthasdef, d.adsrc 58 FROM pg_type t, pg_attribute a LEFT JOIN pg_attrdef d ON (d.adrelid=a.attrelid AND d.adnum=a.attnum) 53 59 WHERE 54 c.relname = '{$tableName}' AND a.attnum > 0 AND a.attrelid = c.oidAND a.atttypid = t.oid60 a.attnum > 0 AND a.attrelid = ".$table->oid." AND a.atttypid = t.oid 55 61 ORDER BY a.attnum"; 62 63 $toReturn=array(); 64 $rs = $this->_connector->query ($sql_get_fields); 65 while ($line = $rs->fetch ()){ 66 $field = new jDbFieldProperties(); 67 $field->name = $line->attname; 68 $field->type = preg_replace('/(\D*)\d*/','\\1',$line->typname); 69 $field->notNull = ($line->attnotnull=='t'); 70 $field->hasDefault = ($line->atthasdef == 't'); 71 $field->default = $line->adsrc; 56 72 57 $rs = $this->_connector->query ($sql_get_fields); 58 $toReturn=array(); 59 while ($result_line = $rs->fetch ()){ 60 $field = new jDbFieldProperties(); 61 if(preg_match('/nextval\(\'(.*?)\.'.$tableName.'_'.$result_line->field.'_seq\'::text\)/', 62 $result_line->adsrc)){ 63 $field->auto_increment=true; 73 if(preg_match('/^nextval\(.*\)$/', $line->adsrc)){ 74 $field->autoIncrement=true; 75 $field->default = ''; 64 76 } 65 66 $field->notnull = ($result_line->notnull==1) ? true:false; 67 $field->type = preg_replace('/(\D*)\d*/','\\1',$result_line->type); 68 if($result_line->length<0) 69 $field->length=null; 70 else 71 $field->length=$result_line->length; 72 $field->name = $result_line->field; 73 $field->primary = ($result_line->atthasdef == 't'); 74 75 $toReturn[$result_line->field]=$field; 77 78 if(in_array($line->attnum, $pkeys)) 79 $field->primary = true; 80 81 $toReturn[$line->attname]=$field; 76 82 } 77 83 trunk/lib/jelix/plugins/db/pgsql/pgsql.dbtools.php
r631 r639 3 3 * @package jelix 4 4 * @subpackage db_driver 5 * @author Croes Gérald, Ferlet Patrice,Laurent Jouanneau5 * @author Laurent Jouanneau 6 6 * @contributor Laurent Jouanneau 7 7 * @contributor Nicolas Jeudy (patch ticket #99) 8 * @copyright 2001-2005 CopixTeam, 2005-2006 Laurent Jouanneau 9 * This class was get originally from the Copix project (CopixDBToolsPostgreSQL, Copix 2.3dev20050901, http://www.copix.org) 10 * Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). 11 * Initial authors of this Copix class are Gerald Croes, Ferlet Patrice and Laurent Jouanneau, 12 * and this class was adapted for Jelix by Laurent Jouanneau 13 * 8 * @copyright 2005-2007 Laurent Jouanneau 14 9 * @link http://www.jelix.org 15 10 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file … … 29 24 protected function _getTableList (){ 30 25 $results = array (); 31 $sql = "SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%'ORDER BY tablename";26 $sql = "SELECT tablename FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema') ORDER BY tablename"; 32 27 $rs = $this->_connector->query ($sql); 33 28 while ($line = $rs->fetch()){ … … 42 37 protected function _getFieldList ($tableName){ 43 38 $results = array (); 44 $sql_get_fields = "SELECT 45 a.attname as Field, t.typname as type, a.attlen as length, a.atttypmod, 46 case when a.attnotnull then 1 else 0 end as notnull, 47 a.atthasdef, 48 (SELECT adsrc FROM pg_attrdef adef WHERE a.attrelid=adef.adrelid AND a.attnum=adef.adnum) AS adsrc 49 FROM 50 pg_attribute a, 51 pg_class c, 52 pg_type t 39 40 // get table informations 41 $sql ='SELECT oid, relhaspkey, relhasindex FROM pg_class WHERE relname = \''.$tableName.'\''; 42 $rs = $this->_connector->query ($sql); 43 if (! ($table = $rs->fetch())) { 44 throw new Exception('dbtools, pgsql: unknow table'); 45 } 46 47 $pkeys = array(); 48 // get primary keys informations 49 if ($table->relhaspkey == 't') { 50 $sql = 'SELECT indkey FROM pg_index WHERE indrelid = '.$table->oid.' and indisprimary = true'; 51 $rs = $this->_connector->query ($sql); 52 $pkeys = preg_split("/[\s]+/", $rs->fetch()->indkey); 53 } 54 55 // get field informations 56 $sql_get_fields = "SELECT t.typname, a.attname, a.attnotnull, a.attnum, 57 a.atthasdef, d.adsrc 58 FROM pg_type t, pg_attribute a LEFT JOIN pg_attrdef d ON (d.adrelid=a.attrelid AND d.adnum=a.attnum) 53 59 WHERE 54 c.relname = '{$tableName}' AND a.attnum > 0 AND a.attrelid = c.oidAND a.atttypid = t.oid60 a.attnum > 0 AND a.attrelid = ".$table->oid." AND a.atttypid = t.oid 55 61 ORDER BY a.attnum"; 62 63 $toReturn=array(); 64 $rs = $this->_connector->query ($sql_get_fields); 65 while ($line = $rs->fetch ()){ 66 $field = new jDbFieldProperties(); 67 $field->name = $line->attname; 68 $field->type = preg_replace('/(\D*)\d*/','\\1',$line->typname); 69 $field->notNull = ($line->attnotnull=='t'); 70 $field->hasDefault = ($line->atthasdef == 't'); 71 $field->default = $line->adsrc; 56 72 57 $rs = $this->_connector->query ($sql_get_fields); 58 $toReturn=array(); 59 while ($result_line = $rs->fetch ()){ 60 $field = new jDbFieldProperties(); 61 if(preg_match('/nextval\(\'(.*?)\.'.$tableName.'_'.$result_line->field.'_seq\'::text\)/', 62 $result_line->adsrc)){ 63 $field->auto_increment=true; 73 if(preg_match('/^nextval\(.*\)$/', $line->adsrc)){ 74 $field->autoIncrement=true; 75 $field->default = ''; 64 76 } 65 66 $field->notnull = ($result_line->notnull==1) ? true:false; 67 $field->type = preg_replace('/(\D*)\d*/','\\1',$result_line->type); 68 if($result_line->length<0) 69 $field->length=null; 70 else 71 $field->length=$result_line->length; 72 $field->name = $result_line->field; 73 $field->primary = ($result_line->atthasdef == 't'); 74 75 $toReturn[$result_line->field]=$field; 77 78 if(in_array($line->attnum, $pkeys)) 79 $field->primary = true; 80 81 $toReturn[$line->attname]=$field; 76 82 } 77 83 trunk/lib/jelix/plugins/db/sqlite/sqlite.dbtools.php
r482 r639 84 84 $field->name = $result_line->name; 85 85 //$p_result_line->length = $length; 86 $field->not _null = ($result_line->notnull != 1);86 $field->notNull = ($result_line->notnull != 1); 87 87 $field->primary = ($result_line->pk == 1); 88 88 89 89 if (preg_match('/^int/i', $field->type)) { 90 90 if ($field->primary) { 91 $field->auto _increment = true;91 $field->autoIncrement = true; 92 92 } else { 93 93 $str = stristr($create_table, $field->name); 94 94 $array = explode(',', $str); 95 95 if (preg_match('/autoincrement/i', $array[0])) { 96 $field->auto _increment = true;96 $field->autoIncrement = true; 97 97 } else { 98 $field->auto _increment = false;98 $field->autoIncrement = false; 99 99 } 100 100 } 101 101 } else { 102 $field->auto _increment = false;102 $field->autoIncrement = false; 103 103 } 104 104 $results[$result_line->name] = $field; trunk/lib/jelix/plugins/db/sqlite/sqlite.dbtools.php
r482 r639 84 84 $field->name = $result_line->name; 85 85 //$p_result_line->length = $length; 86 $field->not _null = ($result_line->notnull != 1);86 $field->notNull = ($result_line->notnull != 1); 87 87 $field->primary = ($result_line->pk == 1); 88 88 89 89 if (preg_match('/^int/i', $field->type)) { 90 90 if ($field->primary) { 91 $field->auto _increment = true;91 $field->autoIncrement = true; 92 92 } else { 93 93 $str = stristr($create_table, $field->name); 94 94 $array = explode(',', $str); 95 95 if (preg_match('/autoincrement/i', $array[0])) { 96 $field->auto _increment = true;96 $field->autoIncrement = true; 97 97 } else { 98 $field->auto _increment = false;98 $field->autoIncrement = false; 99 99 } 100 100 } 101 101 } else { 102 $field->auto _increment = false;102 $field->autoIncrement = false; 103 103 } 104 104 $results[$result_line->name] = $field; trunk/testapp/install/install.mysql.sql
r629 r639 146 146 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , 147 147 `name` VARCHAR( 150 ) NOT NULL , 148 `price` FLOAT NOT NULL148 `price` FLOAT default '0' 149 149 ) TYPE = MYISAM ; 150 150 trunk/testapp/install/install.mysql.sql
r629 r639 146 146 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , 147 147 `name` VARCHAR( 150 ) NOT NULL , 148 `price` FLOAT NOT NULL148 `price` FLOAT default '0' 149 149 ) TYPE = MYISAM ; 150 150 trunk/testapp/modules/jelix_tests/tests/jdao.parser_update.html.php
r638 r639 143 143 144 144 array('<?xml version="1.0"?> 145 <method name="foo" type="update" event Before="true">145 <method name="foo" type="update" eventbefore="true"> 146 146 <values> 147 147 <value property="subject" value="my text" /> … … 172 172 173 173 array('<?xml version="1.0"?> 174 <method name="foo" type="update" event After="true">174 <method name="foo" type="update" eventafter="true"> 175 175 <values> 176 176 <value property="subject" value="my text" /> trunk/testapp/modules/jelix_tests/tests/jdao.parser_update.html.php
r638 r639 143 143 144 144 array('<?xml version="1.0"?> 145 <method name="foo" type="update" event Before="true">145 <method name="foo" type="update" eventbefore="true"> 146 146 <values> 147 147 <value property="subject" value="my text" /> … … 172 172 173 173 array('<?xml version="1.0"?> 174 <method name="foo" type="update" event After="true">174 <method name="foo" type="update" eventafter="true"> 175 175 <values> 176 176 <value property="subject" value="my text" /> trunk/testapp/modules/jelix_tests/tests/jdb.1_queries.html.php
r468 r639 114 114 } 115 115 116 function testTools(){ 117 118 $tools = jDb::getTools($this->dbProfil); 119 $fields = $tools->getFieldList('products'); 120 $structure = '<array> 121 <object key="id" class="jDbFieldProperties"> 122 <string property="type" value="int" /> 123 <string property="name" value="id" /> 124 <boolean property="notNull" value="true" /> 125 <boolean property="primary" value="true" /> 126 <boolean property="autoIncrement" value="true" /> 127 <boolean property="hasDefault" value="false" /> 128 <null property="default" /> 129 </object> 130 <object key="name" class="jDbFieldProperties"> 131 <string property="type" value="varchar" /> 132 <string property="name" value="name" /> 133 <boolean property="notNull" value="true" /> 134 <boolean property="primary" value="false" /> 135 <boolean property="autoIncrement" value="false" />
