Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using a table_prefix containing '.'
  • I'm trying to switch from a MySQL database to a SQLAnywhere database (where I'm not in control the table definition). Database connection and simple queries are working fine.

    Example of a working query for the MySQL database:

      $query = DB::query('SELECT * FROM `Users`');

    Example of a working query for the SQLAnywhere database:  
      
      $query = DB::query('SELECT * FROM "EM"."Users"');

    I notice that I can set the table_prefix for the SQLAnywhere database in the db.php configuration:

      'table_prefix'   => 'EM.',

    However, when I try to use ORM like so:

      $entry = Model_User::find('first');

    I get the following error, but only for the SQLAnywhere database:
      ErrorException [ Error ]: Maximum function nesting level of '100' reached, aborting!

    I don't get this error if I change the prefix (e.g. to 'EM_', but then I obviously get a SQL syntax error instead). 
    Are periods '.' allowed in the table_prefix? Do they need escaping? Is there something else I'm doing wrong?
  • Can you give more information about this error? Which file and line generates that error? Can you give backtrace? ORM uses the DB classes for database interaction, so in theory it should work fine.
  • Thanks. Copied from the error page:

    COREPATH/classes/database/connection.php @ line 649

    644                // Add the table prefix to the table name
    645                $parts[$offset] = $prefix.$parts[$offset];
    646            }
    647
    648            // Quote each of the parts
    649            return implode('.', array_map(array($this, __FUNCTION__), $parts));
    650        }
    651        else
    652        {
    653            return $this->_identifier.$value.$this->_identifier;
    654        }

    Backtrace

    COREPATH/bootstrap.php @ line 36
    31{
    32    // Fire off the shutdown events
    33    Event::shutdown();
    34
    35    load_error_classes();
    36    return \Error::shutdown_handler();
    37});
    38
    39set_exception_handler(function (\Exception $e)
    40{
    41    load_error_classes();
  • I'm also asking for help on the SQLAnywhere forums

    We've established that EM is not a table prefix but the table owner. I'll try to improve my understanding of SQLAnywhere syntax. 
  • mtmacdonaldmtmacdonald
    Accepted Answer
    I no longer require an answer to this. The SQLAnywhere syntax wasn't in fact a table prefix. By logging in as the table owner the owner qualifier ("EM") isn't needed in the query.

    But I'm still interested why putting a period into table_prefix appeared to cause some kind of recursion overflow. 
  • The problem is that when a dot is detected when quoting the identifier, the identifier is split in parts, a table prefix is added, and then it recuses to quote the parts. Which will contain a dot (due to the prefix that was added), which causes the process to repeat itself.

    In most SQL dialects, the dot is used to identify a database name (as in "database.table").

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion