Welcome, Guest. Please login or register.
Did you miss your activation email?
Oct. 11, 2008, 02:01:29 PM
47672 Posts in 10455 Topics by 5339 Members
Latest Member: phamlehoaian
News: New to PRADO? The PRADO blog tutorial is a good start point.
 
The PRADO Community » Prado v3.x » General Discussion » ActiveRecord using table name as `dbname.tblname` « previous next »
Pages: [1] Print
Author Topic: ActiveRecord using table name as `dbname.tblname`  (Read 828 times)
jjmf
Senior Member
***

Karma: 5
Offline Offline

Posts: 221



View Profile
« on: Jan. 09, 2007, 07:56:35 PM »

As I said in the other topic about using 2 databases (http://www.pradosoft.com/forum/index.php/topic,6650.0.html) I was trying to use ActiveRecords.
Here is my ActiveRecord Class:
Code:
class DUserGroupActiveRecord extends TActiveRecord
{
    public $id_grupo = 0;
    public $id_parent = 0;
    public $nome = null;
    public $descricao = null;
    public $roles = null;

    private static $_tablename = 'novodiretor_2006.usuario_grupo'; //table name

    public static function finder()
    {
return self::getRecordFinder('DUserGroupActiveRecord');
    }
}


The problem is that using 'novodiretor_2006.usuario_grupo' as the table name, I get a TDbException:
Code:
TDbCommand failed to prepare the SQL statement "SHOW FULL FIELDS FROM `novodiretor_2006.usuario_grupo`": SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name 'novodiretor_2006.usuario_grupo'

At some point PRADO quote the table name with ` forming the string `novodiretor_2006.usuario_grupo` witch is not a table name
So I tried using  'novodiretor_2006`.`usuario_grupo' as the table name to get `novodiretor_2006`.`usuario_grupo`in the query and that worked but gave me another exception:

Code:
TDbCommand failed to prepare the SQL statement "SELECT `id_grupo`, `id_parent`, `nome`, `descricao`, `roles` FROM novodiretor_2006`.`usuario_grupo WHERE `id_grupo` = :id_grupo": SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usuario_grupo WHERE `id_grupo` = ?' at line 1

Notice that now PRADO didn't quote the table name using ` and in this query try to query table novodiretor_2006`.`usuario_grupo instead `novodiretor_2006`.`usuario_grupo`.

All I need is to make the code somewhere (maybe in the TActiveRecord?) to also quote the table name as the first query (SHOW FULL FIELDS...) do OR to stop adding the ` to the first query.
Logged
sebathi
Senior Member
***

Karma: 2
Offline Offline

Posts: 87



View Profile WWW
« Reply #1 on: Jan. 09, 2007, 09:30:21 PM »

I think you should change the DBConnection of the Record... Just the schema....

Try setting a new connection after you getRecordFinder()
Code:
$finder = ActiveRecord::finder();
$finder->setDbConnection($new TDbConnection($dsn, $user, $pass));

Be sure to make active your connection!, i don't know if you 've to active it before passing it as parameter!

bye!
Logged
jjmf
Senior Member
***

Karma: 5
Offline Offline

Posts: 221



View Profile
« Reply #2 on: Jan. 10, 2007, 11:27:05 AM »

I think it´s a convention issue.
Why quote the table name of the SHOW FULL... query and not the other?
Quote both or quote none.
I think this should solve the problem and allow the use of 'dbname.tablename'.
Logged
wei
PRADO v3.x Developer
Diamond Member
*****

Karma: 65
Offline Offline

Posts: 2872



View Profile
« Reply #3 on: Jan. 11, 2007, 05:28:30 AM »

thanks for the info, updated in the SVN, no quoting of the table name in the "SHOW FULL ..."

you need to quote the table name youself.

The column name are still quoted though.

the docs will now say

"You may need to quote (specific to your database) the value of the $_tablename. E.g. MySQL uses back-ticks, $_tablename = "`database1`.`table1`""

is that correct for MySQL?

Wei.
Logged
jjmf
Senior Member
***

Karma: 5
Offline Offline

Posts: 221



View Profile
« Reply #4 on: Jan. 11, 2007, 12:25:53 PM »

Ok Thanks a lot Wei!

That´s correct for MySQL.
Logged
Pages: [1] Print 
« previous next »
Jump to: