cvs: pear /DB_DataObject DataObject.php /DB_DataObject/DataObject Generator.php /DB_DataObject/tests simple.phpt
| From: | Alan Knowles | Date: | Sun, 18 Jan 2004 02:27:08 +0000 |
| Subject: | cvs: pear /DB_DataObject DataObject.php /DB_DataObject/DataObject Generator.php /DB_DataObject/tests simple.phpt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-15747@lists.php.net to get a copy of this message | ||
alan_k Sat Jan 17 21:27:08 2004 EDT
Modified files:
/pear/DB_DataObject DataObject.php
/pear/DB_DataObject/DataObject Generator.php
/pear/DB_DataObject/tests simple.phpt
Log:
make native key recognision a little better - changes ini file format (key=N|K) - native or key. -
BC protected... - ignores it when it finds a number..
Index: pear/DB_DataObject/DataObject.php
diff -u pear/DB_DataObject/DataObject.php:1.189 pear/DB_DataObject/DataObject.php:1.190
--- pear/DB_DataObject/DataObject.php:1.189 Sat Jan 17 21:00:20 2004
+++ pear/DB_DataObject/DataObject.php Sat Jan 17 21:27:06 2004
@@ -20,7 +20,7 @@
* @package DB_DataObject
* @category DB
*
- * $Id: DataObject.php,v 1.189 2004/01/18 02:00:20 alan_k Exp $
+ * $Id: DataObject.php,v 1.190 2004/01/18 02:27:06 alan_k Exp $
*/
/* =====================================================================================
@@ -56,7 +56,6 @@
define('DB_DATAOBJECT_NOTNULL', 128); // not null col.
-define('DB_DATAOBJECT_NATIVESEQUENCE', 256); // is a native sequence col..
/*
* Define this before you include DataObjects.php to disable overload - if it segfaults due to
Zend optimizer..
@@ -1611,6 +1610,9 @@
$usekey = $keys[0];
+
+
+
if (@$_DB_DATAOBJECT['CONFIG']['sequence_'.$this->__table]) {
$usekey = $_DB_DATAOBJECT['CONFIG']['sequence_'.$this->__table];
}
@@ -1635,12 +1637,30 @@
}
-
+ $realkeys =
$_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
+
+
+ //echo "--keys--\n";
+ //print_R(array($realkeys[$usekey], count($keys))) ;
+ //echo "\n-/keys--\n";
+
+ // if you are using an old ini file - go back to old behaviour...
+ if (is_numeric($realkeys[$usekey])) {
+ $realkeys[$usekey] = 'N';
+ }
+
+ // multiple unique primary keys without a native sequence...
+ if (($realkeys[$usekey] == 'K') && (count($keys) > 1)) {
+ return array(false,false);
+ }
// use native sequence keys...
// technically postgres native here...
// we need to get the new improved tabledata sorted out first.
- if (in_array($dbtype , array( 'mysql', 'mssql')) &&
($table[$usekey] & DB_DATAOBJECT_INT)) {
+ if ( in_array($dbtype , array( 'mysql', 'mssql')) &&
+ ($table[$usekey] & DB_DATAOBJECT_INT) &&
+ (@$realkeys[$usekey] == 'N')
+ ) {
return array($usekey,true);
}
// I assume it's going to try and be a nextval DB sequence.. (not native)
Index: pear/DB_DataObject/DataObject/Generator.php
diff -u pear/DB_DataObject/DataObject/Generator.php:1.44
pear/DB_DataObject/DataObject/Generator.php:1.45
--- pear/DB_DataObject/DataObject/Generator.php:1.44 Fri Jan 9 22:13:13 2004
+++ pear/DB_DataObject/DataObject/Generator.php Sat Jan 17 21:27:07 2004
@@ -14,7 +14,7 @@
// +----------------------------------------------------------------------+
// | Author: Alan Knowles <alan@akbkhome.com>
// +----------------------------------------------------------------------+
-// $Id: Generator.php,v 1.44 2004/01/10 03:13:13 alan_k Exp $
+// $Id: Generator.php,v 1.45 2004/01/18 02:27:07 alan_k Exp $
/**
* Generation tools for DB_DataObject
@@ -327,27 +327,43 @@
}
+
+
if (!strlen(trim($t->name))) {
continue;
}
+
+ if (preg_match('/not_null/i',$t->flags)) {
+ $type += DB_DATAOBJECT_NOTNULL;
+ }
+
$this->_newConfig .= "{$t->name} = $type\n";
$ret['table'][$t->name] = $type;
// i've no idea if this will work well on other databases?
// only use primary key or nextval(), cause the setFrom blocks you setting all key
items...
// if no keys exist fall back to using unique
-
- if (preg_match("/(primary|nextval\()/i",$t->flags)) {
- $keys_out_primary .= "{$t->name} = $type\n";
- $ret_keys_primary[$t->name] = $type;
- } else if (preg_match("/\sunique\s/i",$t->flags)) {
- $keys_out_secondary .= "{$t->name} = $type\n";
- $ret_keys_secondary[$t->name] = $type;
+ //echo "\n{$t->name} => {$t->flags}\n";
+ if (preg_match("/(auto_increment|nextval\()/i",$t->flags)) {
+ // native sequences = 2
+ $keys_out_primary .= "{$t->name} = N\n";
+ $ret_keys_primary[$t->name] = 'N';
+ } else if (preg_match("/(primary|unique)/i",$t->flags)) {
+ // keys.. = 1
+ $keys_out_secondary .= "{$t->name} = K\n";
+ $ret_keys_secondary[$t->name] = 'K';
}
+
+
+
}
$this->_newConfig .= $keys_out . (empty($keys_out_primary) ? $keys_out_secondary :
$keys_out_primary);
$ret['keys'] = empty($keys_out_primary) ? $ret_keys_secondary :
$ret_keys_primary;
+
+
+ //print_r(array("dump for {$this->table}", $ret));
+
return $ret;
Index: pear/DB_DataObject/tests/simple.phpt
diff -u pear/DB_DataObject/tests/simple.phpt:1.16 pear/DB_DataObject/tests/simple.phpt:1.17
--- pear/DB_DataObject/tests/simple.phpt:1.16 Sat Jan 10 00:28:46 2004
+++ pear/DB_DataObject/tests/simple.phpt Sat Jan 17 21:27:08 2004
@@ -231,7 +231,7 @@
$page_module= DB_DataObject::Factory('page_module');
// we should guess better.. but this is a kludgy fix.
- $page_module->sequenceKey(false,false);
+ //$page_module->sequenceKey(false,false);
$page_module->page_id=1;
$page_module->module_id=1;
$page_module->position='top';
@@ -257,9 +257,7 @@
print_R($x);
-
-
-
+