$v = $k;
$keys = $this->keys();
if (!$keys) {
- $this->raiseError("No Keys available for {$this->__table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
+ $this->raiseError("No Keys available for {$this->tableName()}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return false;
}
$k = $keys[0];
}
$sql = 'SELECT ' .
$this->_query['data_select'] . " \n" .
- ' FROM ' . ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table) . " \n" .
+ ' FROM ' . ($quoteIdentifiers ? $DB->quoteIdentifier($this->tableName()) : $this->tableName()) . " \n" .
$this->_join . " \n" .
$this->_query['condition'] . " \n" .
$this->_query['group_by'] . " \n" .
// set link flag
$this->_link_loaded=false;
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
- $this->debug("{$this->__table} DONE", "fetchrow",2);
+ $this->debug("{$this->tableName()} DONE", "fetchrow",2);
}
if (($this->_query !== false) && empty($_DB_DATAOBJECT['CONFIG']['keep_query_after_fetch'])) {
$this->_query = false;
}
- $table = $this->__table;
+ $table = $this->tableName();
if (is_object($from)) {
$table = $from->__table;
$from = array_keys($from->table());
$items = $this->table();
if (!$items) {
- $this->raiseError("insert:No table definition for {$this->__table}",
+ $this->raiseError("insert:No table definition for {$this->tableName()}",
DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return false;
}
$leftq = '';
$rightq = '';
- $seqKeys = isset($_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table]) ?
- $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] :
+ $seqKeys = isset($_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()]) ?
+ $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] :
$this->sequenceKey();
$key = isset($seqKeys[0]) ? $seqKeys[0] : false;
if (($key !== false) && !$useNative) {
if (!$seq) {
- $keyvalue = $DB->nextId($this->__table);
+ $keyvalue = $DB->nextId($this->tableName());
} else {
$f = $DB->getOption('seqname_format');
$DB->setOption('seqname_format','%s');
if ($leftq || $useNative) {
- $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table);
+ $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->tableName()) : $this->tableName());
if (($dbtype == 'pgsql') && empty($leftq)) {
case 'pgsql':
if (!$seq) {
- $seq = $DB->getSequenceName(strtolower($this->__table));
+ $seq = $DB->getSequenceName(strtolower($this->tableName()));
}
$db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver'];
$method = ($db_driver == 'DB') ? 'getOne' : 'queryOne';
if (!$items) {
- $this->raiseError("update:No table definition for {$this->__table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
+ $this->raiseError("update:No table definition for {$this->tableName()}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return false;
}
$datasaved = 1;
// echo " $settings, $this->condition ";
if ($settings && isset($this->_query) && $this->_query['condition']) {
- $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table);
+ $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->tableName()) : $this->tableName());
$r = $this->_query("UPDATE {$table} SET {$settings} {$this->_query['condition']} ");
// don't delete without a condition
if (($this->_query !== false) && $this->_query['condition']) {
- $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table);
+ $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->tableName()) : $this->tableName());
$sql = "DELETE ";
// using a joined delete. - with useWhere..
$sql .= (!empty($this->_join) && $useWhere) ?
$this->_loadConfig();
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
- $this->debug("{$this->__table} $row of {$this->N}", "fetchrow",3);
+ $this->debug("{$this->tableName()} $row of {$this->N}", "fetchrow",3);
}
- if (!$this->__table) {
+ if (!$this->tableName()) {
$this->raiseError("fetchrow: No table", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return false;
}
return false;
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
- $this->debug("{$this->__table} $row of {$this->N}", "fetchrow",3);
+ $this->debug("{$this->tableName()} $row of {$this->N}", "fetchrow",3);
}
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
- $this->debug("{$this->__table} DONE", "fetchrow", 3);
+ $this->debug("{$this->tableName()} DONE", "fetchrow", 3);
}
return true;
}
return false;
}
- $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table);
+ $table = ($quoteIdentifiers ? $DB->quoteIdentifier($this->tableName()) : $this->tableName());
$key_col = empty($keys[0]) ? '' : (($quoteIdentifiers ? $DB->quoteIdentifier($keys[0]) : $keys[0]));
$as = ($quoteIdentifiers ? $DB->quoteIdentifier('DATAOBJECT_NUM') : 'DATAOBJECT_NUM');
// database loaded - but this is table is not available..
if (
- empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])
+ empty($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()])
&& !empty($_DB_DATAOBJECT['CONFIG']['proxy'])
) {
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$x = new DB_DataObject_Generator;
- $x->fillTableSchema($this->_database,$this->__table);
+ $x->fillTableSchema($this->_database,$this->tableName());
}
return true;
}
}
// now have we loaded the structure..
- if (!empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])) {
+ if (!empty($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()])) {
return true;
}
// - if not try building it..
require_once 'DB/DataObject/Generator.php';
$x = new DB_DataObject_Generator;
- $x->fillTableSchema($this->_database,$this->__table);
+ $x->fillTableSchema($this->_database,$this->tableName());
// should this fail!!!???
return true;
}
- $this->debug("Cant find database schema: {$this->_database}/{$this->__table} \n".
+ $this->debug("Cant find database schema: {$this->_database}/{$this->tableName()} \n".
"in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5);
// we have to die here!! - it causes chaos if we dont (including looping forever!)
$this->raiseError( "Unable to load schema for database and table (turn debugging up to 5 for full error message)", DB_DATAOBJECT_ERROR_INVALIDARGS, PEAR_ERROR_DIE);
*/
function tableName()
{
+ global $_DB_DATAOBJECT;
$args = func_get_args();
if (count($args)) {
$this->__table = $args[0];
}
+ if (!empty($_DB_DATAOBJECT['CONFIG']['portability']) && $_DB_DATAOBJECT['CONFIG']['portability'] & 1) {
+ return strtolower($this->__table);
+ }
return $this->__table;
}
$this->_connect();
}
- if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])) {
- return $_DB_DATAOBJECT['INI'][$this->_database][$this->__table];
+ if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()])) {
+ return $_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()];
}
$this->databaseStructure();
$ret = array();
- if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])) {
- $ret = $_DB_DATAOBJECT['INI'][$this->_database][$this->__table];
+ if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()])) {
+ $ret = $_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()];
}
return $ret;
if (!isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5])) {
$this->_connect();
}
- if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
- return array_keys($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"]);
+ if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"])) {
+ return array_keys($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"]);
}
$this->databaseStructure();
- if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
- return array_keys($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"]);
+ if (isset($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"])) {
+ return array_keys($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"]);
}
return array();
}
if (count($args)) {
$args[1] = isset($args[1]) ? $args[1] : false;
$args[2] = isset($args[2]) ? $args[2] : false;
- $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = $args;
+ $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = $args;
}
- if (isset($_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table])) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table];
+ if (isset($_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()])) {
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()];
}
// end call setting (eg. $do->sequenceKeys(a,b,c); )
$keys = $this->keys();
if (!$keys) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table]
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()]
= array(false,false,false);
}
$seqname = false;
- if (!empty($_DB_DATAOBJECT['CONFIG']['sequence_'.$this->__table])) {
- $seqname = $_DB_DATAOBJECT['CONFIG']['sequence_'.$this->__table];
+ if (!empty($_DB_DATAOBJECT['CONFIG']['sequence_'.$this->tableName()])) {
+ $seqname = $_DB_DATAOBJECT['CONFIG']['sequence_'.$this->tableName()];
if (strpos($seqname,':') !== false) {
list($usekey,$seqname) = explode(':',$seqname);
}
// if the key is not an integer - then it's not a sequence or native
if (empty($table[$usekey]) || !($table[$usekey] & DB_DATAOBJECT_INT)) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = array(false,false,false);
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = array(false,false,false);
}
if (!empty($_DB_DATAOBJECT['CONFIG']['ignore_sequence_keys'])) {
$ignore = $_DB_DATAOBJECT['CONFIG']['ignore_sequence_keys'];
if (is_string($ignore) && (strtoupper($ignore) == 'ALL')) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = array(false,false,$seqname);
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = array(false,false,$seqname);
}
if (is_string($ignore)) {
$ignore = $_DB_DATAOBJECT['CONFIG']['ignore_sequence_keys'] = explode(',',$ignore);
}
- if (in_array($this->__table,$ignore)) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = array(false,false,$seqname);
+ if (in_array($this->tableName(),$ignore)) {
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = array(false,false,$seqname);
}
}
- $realkeys = $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
+ $realkeys = $_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"];
// if you are using an old ini file - go back to old behaviour...
if (is_numeric($realkeys[$usekey])) {
// multiple unique primary keys without a native sequence...
if (($realkeys[$usekey] == 'K') && (count($keys) > 1)) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = array(false,false,$seqname);
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = array(false,false,$seqname);
}
// use native sequence keys...
// technically postgres native here...
($table[$usekey] & DB_DATAOBJECT_INT) &&
isset($realkeys[$usekey]) && ($realkeys[$usekey] == 'N')
) {
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = array($usekey,true,$seqname);
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = array($usekey,true,$seqname);
}
// if not a native autoinc, and we have not assumed all primary keys are sequence
if (($realkeys[$usekey] != 'N') &&
return array(false,false,false);
}
// I assume it's going to try and be a nextval DB sequence.. (not native)
- return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->__table] = array($usekey,false,$seqname);
+ return $_DB_DATAOBJECT['SEQUENCE'][$this->_database][$this->tableName()] = array($usekey,false,$seqname);
}
if (!$dsn) {
if (!$this->_database && !empty($this->__table)) {
- $this->_database = isset($options["table_{$this->__table}"]) ? $options["table_{$this->__table}"] : null;
+ $this->_database = isset($options["table_{$this->tableName()}"]) ? $options["table_{$this->tableName()}"] : null;
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Checking for database specific ini ('{$this->_database}') : database_{$this->_database} in options","CONNECT");
}
$kSql = $quoteIdentifiers
- ? ( $DB->quoteIdentifier($this->__table) . '.' . $DB->quoteIdentifier($k) )
- : "{$this->__table}.{$k}";
+ ? ( $DB->quoteIdentifier($this->tableName()) . '.' . $DB->quoteIdentifier($k) )
+ : "{$this->tableName()}.{$k}";
if ($table === '') {
- if (is_a($this,'DB_DataObject') && strlen($this->__table)) {
- $table = $this->__table;
+ if (is_a($this,'DB_DataObject') && strlen($this->tableName())) {
+ $table = $this->tableName();
} else {
return DB_DataObject::raiseError(
"factory did not recieve a table name",
$cfg = &$_DB_DATAOBJECT['CONFIG'];
// loaded and available.
- if (isset($lcfg[$this->_database][$this->__table])) {
- return $lcfg[$this->_database][$this->__table];
+ if (isset($lcfg[$this->_database][$this->tableName()])) {
+ return $lcfg[$this->_database][$this->tableName()];
}
// loaded
return null;
}
- if (isset($lcfg[$this->_database][$this->__table])) {
- return $lcfg[$this->_database][$this->__table];
+ if (isset($lcfg[$this->_database][$this->tableName()])) {
+ return $lcfg[$this->_database][$this->tableName()];
}
return array();
$ar[1] = explode(',', $ar[1]);
}
- if ($ar[0] != $this->__table) {
+ if ($ar[0] != $this->tableName()) {
continue;
}
if ($ofield === false) {
$this->raiseError(
- "joinAdd: {$obj->__table} has no link with {$this->__table}",
+ "joinAdd: {$obj->__table} has no link with {$this->tableName()}",
DB_DATAOBJECT_ERROR_NODATA);
return false;
}
- $table = $this->__table;
+ $table = $this->tableName();
if ($quoteIdentifiers) {
$joinAs = $DB->quoteIdentifier($joinAs);
$items = $this->table();
if (!$items) {
$this->raiseError(
- "setFrom:Could not find table definition for {$this->__table}",
+ "setFrom:Could not find table definition for {$this->tableName()}",
DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return;
}
function _createTableList()
{
$this->_connect();
+
$options = &PEAR::getStaticProperty('DB_DataObject','options');
+
+
$__DB= &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5];
$db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver'];
foreach($this->tables as $table) {
if (isset($options['generator_include_regex']) &&
- !preg_match($options['generator_include_regex'],$table)) {
+ !preg_match($options['generator_include_regex'],$table)) {
$this->debug("SKIPPING (generator_include_regex) : $table");
continue;
- } else if (isset($options['generator_exclude_regex']) &&
- preg_match($options['generator_exclude_regex'],$table)) {
+ }
+
+ if (isset($options['generator_exclude_regex']) &&
+ preg_match($options['generator_exclude_regex'],$table)) {
continue;
}
// postgres strip the schema bit from the
if (!empty($options['generator_strip_schema'])) {
- $bits = explode('.', $table,2);
- $table = $bits[0];
- if (count($bits) > 1) {
- $table = $bits[1];
+ $strip = $options['generator_strip_schema'];
+ if (!is_string($strip) || preg_match($strip, $table)) {
+ $bits = explode('.', $table,2);
+ $table = $bits[0];
+ if (count($bits) > 1) {
+ $table = $bits[1];
+ }
}
}
+ $this->debug("EXTRACTING : $table");
$quotedTable = !empty($options['quote_identifiers_tableinfo']) ?
$__DB->quoteIdentifier($table) : $table;
if (is_object($defs) && is_a($defs,'PEAR_Error')) {
// running in debug mode should pick this up as a big warning..
+ $this->debug("Error reading tableInfo: $table");
$this->raiseError('Error reading tableInfo, '. $defs->toString());
continue;
}
echo "WARNING: cant handle non-mysql and pgsql introspection for defaults.";
return; // cant handle non-mysql introspection for defaults.
}
-
+ $this->debug("generateForeignKeys: Start");
$DB = $this->getDatabaseConnection();
$fk = array();
// it's created on the fly!
$options = PEAR::getStaticProperty('DB_DataObject','options');
- if (empty($options['schema_location'])) {
+ if (!empty($options['schema_location'])) {
+ $file = "{$options['schema_location']}/{$this->_database}.links.ini";
+ } elseif (isset($options["ini_{$this->_database}"])) {
+ $file = preg_replace('/\.ini/','.links.ini',$options["ini_{$this->_database}"]);
+ } else {
+ $this->debug("generateForeignKeys: SKIP - schema_location or ini_{database} was not set");
return;
}
-
-
- $file = "{$options['schema_location']}/{$this->_database}.links.ini";
+
if (!file_exists(dirname($file))) {
- require_once 'System.php';
- System::mkdir(array('-p','-m',0755,dirname($file)));
+ mkdir(dirname($file),0755, true);
}
$this->debug("Writing ini as {$file}\n");