Dan Kalowsky wrote:

>Hi Kevin
>
>On Sun, 18 Aug 2002, Kevin Gordon wrote:
>
>  
>
>>The first two functions return "resource" and the second two functions
>>return "int". Is there any difference?
>>    
>>
>
>In this case, not really.  I think I should probably update some of the
>documentation it seems.
>
>  
>
>>Using a postgresql database odbc_tables works fine. But with
>>odbc_primarykeys I can not find a result.
>>    
>>
>
>Either A) you've found a bug, or B) you're using it wrong.  I'm going to
>guess B at this time as it does seem to work.  Although there is an open
>bug about it not working for others.
>
>  
>
>>---------------------------------------------------------------<
>>    
>>
>Dan Kalowsky                   "A little less conversation,
>http://www.deadmime.org/~dank   a little more action."
>[EMAIL PROTECTED]       - "A Little Less Conversation",
>[EMAIL PROTECTED]                       Elvis Presley
>
>
>
>  
>
Hi Dan. Thank you for your comments. Here is the code that I am 
experimenting with:

/*! <method name="kgtables" access="public">
<summary>Returns a list of the table names contained in a 
database.</summary>
<returns type="object" />
</method> !*/
function kgtables () {
if ($this->connection)
{
$tablelist = odbc_tables($this->connection);
$i = 1;
while (odbc_fetch_row($tablelist))
{
if (odbc_result($tablelist, 4) == "TABLE")
{
// echo "" . odbc_result($tablelist, 3) ."<br>";
$obj->{$i} = odbc_result ($tablelist, 3);
$i++;
}
}
$this->num_tables = $i - 1;
return $obj;
}
else
{
return 0;
}
}

/*! <method name="kgprimarykeys" access="public">
<summary>Returns a result set listing primary key fields.</summary>
<param name="tablename" type="string" />
<returns type="object" />
</method> !*/
function kgprimarykeys ($tablename = "") {
if ( $this->connection && $tablename != "" )
{
if (!($keylist = odbc_primarykeys ($this->connection, "kgdb", "kevin", 
$tablename )))
{
$keylist = "";
$sql = "SELECT " .
"ic.relname AS index_name, " .
"bc.relname AS tab_name, " .
"ta.attname AS column_name, " .
"i.indisunique AS unique_key, " .
"i.indisprimary AS primary_key " .
"FROM " .
"pg_class bc, " .
"pg_class ic, " .
"pg_index i, " .
"pg_attribute ta, " .
"pg_attribute ia " .
"WHERE " .
"bc.oid = i.indrelid " .
"AND ic.oid = i.indexrelid " .
"AND ia.attrelid = i.indexrelid " .
"AND ta.attrelid = bc.oid " .
"AND bc.relname = '" . $tablename . "' " .
"AND ta.attrelid = i.indrelid " .
"AND ta.attnum = i.indkey[ia.attnum-1] " .
"ORDER BY " .
"index_name, tab_name, column_name";
$keylist = odbc_exec ($this->connection, $sql);
// odbc_result_all ($keylist);
}
$i = 1;
while (odbc_fetch_row($keylist))
{
if (odbc_result($keylist, 5) == "1")
{
// echo " " . odbc_result($keylist, 3) ."<br>";
$obj->{$i} = odbc_result ($keylist, 3);
$i++;
}
}
$this->num_primarykeys = $i - 1;
odbc_free_result ($keylist);
return $obj;
}
else
{
echo 'Error: failed to name the primary keys in ODBC_Driver.php ' . 
$keys . '<br />';
return 0;
}
}

Any comments would be appreciated. The ODBC driver links with 
Postgresql. I will remove the SQL select statement once I have succeeded 
with the odbc_primarykeys function.
Regards,
Kevin



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to