Re: [phplib] Accessing fields with reserved names etc. From: Jesse Swensen (swensenj <email protected>)
Date: 11/18/00

First I have to say it is REALLY BAD form to use any reserved words as
column names even if you can work around it. It would be better to change
the column name. In the long run it will save you much grief.

That being said, you should be able to do something like this

SELECT
    "DATE" mydate,
...

and then write
echo $q->f("mydate")

What you have done is create an ALIAS for "DATE" called mydate.

The table_name function will only query for tables owned by the user. When
you dig into the code you will see

  function table_names() {
   $this->connect();
   $this->query("
   SELECT table_name,tablespace_name
     FROM user_tables");

Now you can see that it uses USER_TABLES which will not get tables you can
"see" but only that you own. As I see it, you have a couple of options (I
am sure there are others but I will suggest a couple)

First, sub class the db_sql class and replace the table function or just
roll your own function as you have done.

-- 
Jesse Swensen
swensenj <email protected>

> From: "nemholt_jf" <email protected> > Date: Fri, 17 Nov 2000 15:14:28 +0100 > To: phplib <email protected> > Subject: [phplib] Accessing fields with reserved names etc. > > > > 11/17/2000 03:14 PM > (subscript: Jesper Frank Nemholt <email protected>) > Hi! > > I've just implemented PHPLib in a application that used to be hardcoded to > MySQL. > The goal was to make it compatible with at least Oracle & MySQL, since it's > going to run on Oracle8 in near future. > > I ran in to a few problems, mostly related to the different way Oracle handles > various stuff and missing features in PHPLib or Oracle compared to normal > MySQL > calls in PHP. > It's the first time I use PHPLib, so many of my problems are probably in the > FAQ > category. > > > First the problem I couldn't solve : > > All my tables start with a field/column named DATE. > This is a reserved word in Oracle, and when doing a SELECT, I have to write > "DATE" to make it work. > Problem is, that when I later try to access the field using : > > q->f("DATE") > > ...it doesn't work. I've tried q->f('"DATE'") and other variants, but none of > them works. > Is there a solution for this ? > > > Secondly, according to the documentation of PHPLib, table_names() should be > implemented in db_oci8.inc and db_oracle.inc, but it somehow doesn't work for > me. > Can anyone verify that it actually works on Oracle8 ? > I came up with this alternative solution, but I'd prefer to use a standard > PHPLib call instead : > > if ($q->type == "oci8") > { > $tmp = "'" . $ORACLE_SID . "'"; > $query = sprintf("SELECT table_name FROM all_tables WHERE owner=$tmp"); > $q->query($query); > $result = array(); > while ($q->next_record()) > { > array_push($result, strtolower($q->f("table_name"))); > } > } > else > { > $result = $q->table_names(); > } > > > > At last, I needed something like MySQLs DESCRIBE table and ended up with this > solution, which is just as ugly as my other solution : > > if ($q->type == "oci8") > { > $SID = "'" . $ORACLE_SID . "'"; > $tb_name = "'" . strtoupper($HTTP_POST_VARS["table_table"]) . "'"; > $query = sprintf("SELECT column_name,data_type FROM all_tab_columns WHERE > owner=$SID AND table_name=$tb_name"); > } > elseif ($q->type == "mysql") > { > $query = sprintf("DESCRIBE $table"); > } > else > { > echo "Unsupported database<BR>\n"; > } > > > Regarding $q->type; isn't it supposed to be set to the active database type > autmagically. In my setup it's empty allways, so I had to set it by hand. > > > If anyone has better ways for the solutions above, I'd like to hear. > > Please CC to my mail address. > > > /Jesper > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: phplib-unsubscribe <email protected> > For additional commands, e-mail: phplib-help <email protected> > >

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>