Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Bug Reports » Database/Table Import Error (BUG Report)
Database/Table Import Error [message #2336] Thu, 05 November 2009 17:52 Go to next message
ljkbrost is currently offline  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 #2337 is a reply to message #2336] Thu, 05 November 2009 18:44 Go to previous messageGo to next message
ljkbrost is currently offline  ljkbrost
Messages: 59
Registered: April 2006
Member
It looks like this problem is also happening with:

dict_column_s01.class.inc

On a quick check on the directory there are a lot of dbprefix variables used in the various tables. Not sure if there will be any other issues.

Cheers,


Kyle Brost
----
Re: Database/Table Import Error [message #2339 is a reply to message #2336] Fri, 06 November 2009 05:43 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2275
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.


Re: Database/Table Import Error [message #2341 is a reply to message #2339] Fri, 06 November 2009 09:12 Go to previous messageGo to next message
ljkbrost is currently offline  ljkbrost
Messages: 59
Registered: April 2006
Member
The password doesn't matter as the system is a development box.

if (eregi('^(127.0.0.1|localhost|desktop|laptop)$', $_SERVER['SERVER_NAME'])) { // this is for my PC
$GLOBALS['dbusername'] = '****';
$GLOBALS['dbuserpass'] = '****';
$GLOBALS['dbprefix'] = null;
// set these only if secure HTTPS protocol is available on your server
$GLOBALS['http_server'] = '';
$GLOBALS['https_server'] = '';
$GLOBALS['https_server_suffix'] = '';
} else {
// this is for my shared web host
$GLOBALS['dbusername'] = 'radicore';
$GLOBALS['dbuserpass'] = 'radi.core.2009';
$GLOBALS['dbprefix'] = 'dev1_';
// set these only if secure HTTPS protocol is available on your server
$GLOBALS['http_server'] = '';
$GLOBALS['https_server'] = '';
$GLOBALS['https_server_suffix'] = '';
} // if

The naming of the databases:

dev1_audit
dev1_customer
dev1_dict
dev1_menu
dev1_workflow

I am running PHP 5.3.

Cheers,


Kyle Brost
----
www.softelephant.com
Re: Database/Table Import Error [message #2342 is a reply to message #2341] Fri, 06 November 2009 09:43 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2275
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.


Re: Database/Table Import Error [message #2343 is a reply to message #2342] Fri, 06 November 2009 10:27 Go to previous messageGo to next message
ljkbrost is currently offline  ljkbrost
Messages: 59
Registered: April 2006
Member
This is what $this->_ddl_showDatabases($dbprefix)

Array ( [0] => dev1_audit
[1] => dev1_customer
[2] => dev1_dict
[3] => dev1_menu
[4] => dev1_workflow )

$dbnames contains:

Array ( [customer] => customer )

See no issue there.

Drilling down into dict_table_s01 the _cm_getInitialDataMultiple function ultimately calls $this->_ddl_showTables. Inside the MySQL, MySQLi, and PgSql versions the function grabs the dbprefix from $GLOBALS. Loooking at the Oracle versions there is no reference to the dbprefix in the file.

Are you using the Oracle version and hence the reason things work for you and not me? I don't have oracle installed anywhere to test this out.

I know the dbprefix gets appended in dict_table_s01 as well in the mysql calls to _ddl_showTables. Hence the doubling up of dbprefix.

Hope that helps,


Kyle Brost
----
www.softelephant.com
Re: Database/Table Import Error [message #2344 is a reply to message #2343] Fri, 06 November 2009 12:49 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2275
Registered: April 2006
Location: Surrey, UK
Senior Member
I do all my development and testing with MySQL, which is what I assume you are using. I only play with the PostgreSQL and Oracle databases when a problem arises, or when introducing new functionality.

If the output from the call to _loadDatabases() is a dbname of 'customer', then where does the 'dev1_' prefix get added in twice? I have just tried it on my system by erasing the details of a database with a prefix, then importing it again, and it worked flawlessly (apart from the bug I fixed earlier Embarassed ).

Can you step through with your debugger to see where the prefix is being used twice?


Re: Database/Table Import Error [message #2345 is a reply to message #2344] Fri, 06 November 2009 13:42 Go to previous messageGo to next message
ljkbrost is currently offline  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 Go to previous message
AJM is currently offline  AJM
Messages: 2275
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.


Previous Topic: Error messages not being returned to previous screen
Next Topic: std.update3.inc confusion
Goto Forum:
  


Current Time: Sun Nov 28 15:15:29 EST 2021

Total time taken to generate the page: 0.01018 seconds