Database/Table Import Error [message #2336] |
Thu, 05 November 2009 17:52 |
ljkbrost
Messages: 59 Registered: April 2006
|
Member |
|
|
Radicore Version: 1.53.0
I cannot import the databases for a new subsystem. The radicore framework dies with a fatal error and I have attached the errorlog.html to this message.
Upon investigation it looks like it has to do with the database prefix. My tables are prefixed with 'dev1_' and when I go to import the database the system recognizes the missing DB and starts the import. When it gets to the tables it looking for 'dev1_dev1_customer'. It should be 'dev1_customer'.
Looking at dict_table_s01.class.inc the problem appear on line 25:
$fieldarray = array();
$array = $this->_ddl_showTables($dbprefix.$dbname);
The system is trying to 'showTables' for 'dev1_' . 'dev1_customer'. Removing the $dbprefix from the line fixes the problem and allows me to import the database and tables with no problem. The $dbname already is fully qualified with the prefix.
Cheer,
Kyle Brost
|
|
|
|
Re: Database/Table Import Error [message #2339 is a reply to message #2336] |
Fri, 06 November 2009 05:43 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I have tried this on my PC and I cannot reproduce the fault. It may be because of something in your config.inc file, so can you post me its contents? You can block out your username and password.
The way the $dbprefix feature is supposed to work is as follows:
- you have a database called 'foobar'
- it is imported into the data dictinary as 'foobar'
- you may create a copy of this database called 'dev1_foobar', but in order to access it your config.inc file should identify it as $dbname='foobar' and $dbprefix='dev1_'
- the dictionary import functions will use $dbprefix to access the database schema, but will use only $dbname within the dictionary database.
This means that you can have as may copies of 'foobar' as you like, such as 'dev1_foobar', 'dev2_foobar', 'this_foobar' and 'that_foobar', but the data dictionary will only have one set of details under the name 'foobar'. At runtime you can only access one of these databases, so you set the value of $dbprefix in your config.inc file accordingly.
If the dbname in the data dictionary includes the dbprefix then you have done something wrong.
I did find one small problem in the dict_table_key class, so I have attached an updated file.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Database/Table Import Error [message #2342 is a reply to message #2341] |
Fri, 06 November 2009 09:43 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
There is nothing wrong with your config.inc file, and I cannot reproduce this fault on my PC.
The problem lies somewhere in the _loadDatabases() method inside 'dict_dataBase_s01.class.inc' where it looks for database names with the prefix, then strips off the prefix for internal use. All database names which appear in the dropdown list should not include the prefix.
You need to step through with your debugger to see what the code is doing with the prefix.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: Database/Table Import Error [message #2345 is a reply to message #2344] |
Fri, 06 November 2009 13:42 |
ljkbrost
Messages: 59 Registered: April 2006
|
Member |
|
|
Inside: dml.mysqli.class.inc
function ddl_showTables ($dbname)
// obtain a list of tables within the specified database.
{
// connect to database
$this->connect($dbname) or trigger_error($this, E_USER_ERROR);
$array = array();
$dbname = $GLOBALS['dbprefix'] .$dbname;
// build the query string and run it
$this->query = 'SHOW TABLES FROM "' .$dbname .'"';
$result = mysqli_query($this->dbconnect, $this->query) or trigger_error($this, E_USER_ERROR);
$count = mysqli_num_rows($result);
// write query to log file, if option is turned on
logSqlQuery ($dbname, null, $this->query, $count);
// convert result set into a simple indexed array for each row
while ($row = mysqli_fetch_row($result)) {
$array[] = $row[0];
} // while
mysqli_free_result($result);
return $array;
} // ddl_showTables
Notice the $dbname variable gets reassigned to:
$dbname = $GLOBAL['dbprefix'] . $dbname;
When it comes into this function it already has the dbprefix attached to it from the _cm_getInitialDataMultiple function of dict_table_s01.class.inc. (Noted below).
function _cm_getInitialDataMultiple ($fieldarray)
// Perform custom processing prior to insertMultiple.
// $fieldarray contains data from the initial $where clause.
{
// get list of existing table names
if (!is_string(key($fieldarray))) {
$fieldarray = $fieldarray[0];
} // if
$dbname = $fieldarray['database_id'];
$dbprefix = dict_findDBPrefix($dbname);
$array = $this->_ddl_showTables($dbprefix.$dbname);
// filter out those that already exist in DICT database
$i = 0;
foreach ($array as $tablename) {
$tablename = strtolower($tablename);
$count = $this->getCount("database_id='$dbname' AND table_id='$tablename'");
if ($count == 0) {
// insert details of new database
$fieldarray[$i]['database_id'] = $dbname;
$fieldarray[$i]['table_id'] = $tablename;
$fieldarray[$i]['table_desc'] = ucwords(str_replace('_', ' ', $tablename));
$i++;
} // if
} // foreach
return $fieldarray;
} // _cm_getInitialDataMultiple
The call to $this->_ddl_showTables($dbprefix.$dbname); adds the prefix and then the call within Default_Table::_ddl_showTables that calls mysql::ddl_showTables does the same thing. Hence the double append.
Does that help?
Kyle Brost
----
www.softelephant.com
|
|
|
Re: Database/Table Import Error [message #2346 is a reply to message #2345] |
Fri, 06 November 2009 15:49 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
Ah ha! I've found the problem. I was using a config.inc file which used the multiple servers option, as described in FAQ92. This had a value for $servers[0]['dbprefix'] but nothing for $GLOBALS['dbprefix'], so I didn't spot that dbprefix was being added in twice.
The solution is to remove the following line
$dbname = $GLOBALS['dbprefix'] .$dbname;
from the ddl_showColumns() and ddl_showTables() methods inside your copy of the 'dml.mysql[i].class.inc' file.
An updated copy of 'dml.mysqli.class.inc' is attached.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|