user3032973
user3032973

Reputation: 415

PHP LEAP ORM query with table alias

Currently I am using the LEAP ORM for kohana and am attempting to create some sql queries. These queries are going against an oracle database. I am able to connect and query this database successfully. However when I attempt to alias tables and reference columns using those alias, the syntax is not working. Below is what I currently have

     return $this->db->query("select HRB.PARENT_COMPANY 
FROM COMPANY_TABLE HRB 
INNER JOIN 
OTHER_TABLE BTR 
HRB.ID = BTR.WID 
WHERE HRB.NAME LIKE '".$VAL."%;");

It doesnt seem to like HRB.PARENT

Error message

ErrorException [ Warning ]: oci_execute(): ORA-00904: "GPR"."GIS_PROP_FCNB_1": invalid identifier
MODPATH\leap\classes\Base\DB\Oracle\DataReader\Standard.php [ 57 ]
52          throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => $reason));
53      }
54      if ( ! is_integer($mode)) {
55          $mode = 32;
56      }
57      if ( ! oci_execute($command, $mode)) {
58          $error = @oci_error($command);
59          $reason = (is_array($error) AND isset($error['message']))
60              ? $error['message']
61              : 'Unable to perform command.';
62          throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => $reason));

If table alias is removed the following error is thrown

ErrorException [ Warning ]: oci_execute(): ORA-00918: column ambiguously defined

Upvotes: 0

Views: 303

Answers (1)

Robert Harvey
Robert Harvey

Reputation: 180798

This page says that Table Aliases are not supported in DB_ORM.

Try this:

return $this->db->query("select COMPANY_TABLE.PARENT_COMPANY 
FROM COMPANY_TABLE
INNER JOIN OTHER_TABLE COMPANY_TABLE.ID = OTHER_TABLE.WID 
WHERE OTHER_TABLE.NAME LIKE '".$VAL."%;");

Upvotes: 1

Related Questions