/** * @see TableInfo::initPrimaryKey() */ protected function initPrimaryKey() { include_once 'creole/metadata/PrimaryKeyInfo.php'; // columns have to be loaded first if (!$this->colsLoaded) { $this->initColumns(); } $result = @odbc_primarykeys($this->dblink, $this->dbname, '', $this->name); while (odbc_fetch_row($result)) { $name = odbc_result($result, 'COLUMN_NAME'); if (!isset($this->primaryKey)) { $this->primaryKey = new PrimaryKeyInfo($name); } $this->primaryKey->addColumn($this->columns[$name]); } @odbc_free_result($result); $this->pkLoaded = true; }
function MetaPrimaryKeys($table) { global $ADODB_FETCH_MODE; if ($this->uCaseTables) { $table = strtoupper($table); } $schema = ''; $this->_findschema($table, $schema); $savem = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $qid = @odbc_primarykeys($this->_connectionID, '', $schema, $table); if (!$qid) { $ADODB_FETCH_MODE = $savem; return false; } $rs = new ADORecordSet_odbc($qid); $ADODB_FETCH_MODE = $savem; if (!$rs) { return false; } $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; $arr =& $rs->GetArray(); $rs->Close(); //print_r($arr); $arr2 = array(); for ($i = 0; $i < sizeof($arr); $i++) { if ($arr[$i][3]) { $arr2[] = $arr[$i][3]; } } return $arr2; }
function get_cols(&$conn, $table) { global $dbname; $cols = array(); $keys = array(); // $table = 'dbo.'.$table; $r = odbc_primarykeys($conn, $dnname, '%', $table); while ($row = odbc_fetch_array($r)) { $keys[] = $row['COLUMN_NAME']; } $r = odbc_columns($conn, $dbname, '%', $table, '%'); while ($row = odbc_fetch_array($r)) { // print_r($row); $c = array(); $c['name'] = htmlentities($row['COLUMN_NAME']); $c['type'] = $row['TYPE_NAME']; $c['special'] = ''; if (isset($row['COLUMN_SIZE'])) { $c['special'] = $row['COLUMN_SIZE']; } if (isset($row['LENGTH'])) { $c['special'] = $row['LENGTH']; } $c['nn'] = $row['NULLABLE'] == 0; $c['default'] = str_replace("'", '', $row['COLUMN_DEF']); $c['pk'] = in_array($row['COLUMN_NAME'], $keys); $cols[] = $c; } return $cols; }
function GetColumnInfo($TableName) { switch ($this->dbc->Dialect) { case "TSQL": $qualifier = $this->dbc->dbDefault; $schema = "%"; break; case "Access": $qualifier = $this->dbc->dsn; $schema = ""; break; default: return null; } echo "<p>GetColumnInfo: " . $qualifier . "." . $schema . "." . $TableName . "</p>"; $rsMain = odbc_columns($this->dbc->dbMain, $qualifier, $schema, $TableName); //odbc_result_all($rsMain); if (!$rsMain) { return null; } $arColumns = array(); while ($this->FetchAssoc($rsMain, $row)) { if ($row["TABLE_NAME"] != $TableName) { continue; } $colinfo = new dbColumn(); //echo "<p>GetColumnInfo: ".$row["COLUMN_NAME"].':'.$row["TYPE_NAME"]."</p>"; $colinfo->ColName = $row["COLUMN_NAME"]; $colinfo->ColType = $row["TYPE_NAME"]; if (array_key_exists("PRECISION", $row)) { $colinfo->ColLength = $row["PRECISION"]; } else { if (array_key_exists("COLUMN_SIZE", $row)) { $colinfo->ColLength = $row["COLUMN_SIZE"]; } } $colinfo->Nullable = $row["NULLABLE"] == "YES"; $colinfo->IsPKey = false; $colinfo->Writeable = $row["TYPE_NAME"] != 'int identity'; array_push($arColumns, $colinfo); } $this->FreeResult($rsMain); //$rsMain=odbc_columnprivileges($this->dbc->dbMain, $qualifier, $schema, $TableName,"%"); //odbc_result_all($rsMain); //$this->FreeResult($rsMain); $rsMain = odbc_primarykeys($this->dbc->dbMain, $qualifier, $schema, $TableName); if ($rsMain) { while ($this->FetchAssoc($rsMain, $row)) { $colname = $row["COLUMN_NAME"]; //echo "<p>GetColumnInfo pk: ".$colname."</p>"; for ($i = 0; $i < count($arColumns); $i++) { if ($arColumns[$i]->ColName == $colname) { $arColumns[$i]->IsPKey = true; break; } } } $this->FreeResult($rsMain); } return $arColumns; }
} var_dump($rr); } // foreignkeys $rh = odbc_foreignkeys($r, '', '', '', '', '', ''); //var_dump($rh); echo "resource? " . is_resource($rh) . "\n"; if ($rh == NULL) { echo odbc_errormsg(); } else { while ($rr = odbc_fetch_array($rh)) { var_dump($rr); } } // primarykeys $rh = odbc_primarykeys($r, '', 'test', 'my_table'); //var_dump($rh); echo "resource? " . is_resource($rh) . "\n"; if ($rh == NULL) { echo odbc_errormsg(); } else { while ($rr = odbc_fetch_array($rh)) { var_dump($rr); } } // tables $rh = odbc_tables($r); //var_dump($rh); echo "resource? " . is_resource($rh) . "\n"; if ($rh == NULL) { echo odbc_errormsg();
/** * list all indexes in a table * * @param string $table name of table that should be used in method * * @return mixed array of index names on success, a MDB2 error on failure * @access public */ function listTableIndexes($table) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $key_name = 'INDEX_NAME'; $pk_name = 'PK_NAME'; if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { if ($db->options['field_case'] == CASE_LOWER) { $key_name = strtolower($key_name); $pk_name = strtolower($pk_name); } else { $key_name = strtoupper($key_name); $pk_name = strtoupper($pk_name); } } //$table = $db->quote($table, 'text'); //$query = "EXEC sp_statistics @table_name=$table"; $table = "V_PARTNERSTAMM"; $res = odbc_statistics($db->connection, $db->dsn[username], $db->dsn[username], $table, 0, 0); $indexes = array(); while ($data = odbc_fetch_array($res)) { $indexes[] = $data[$key_name]; } $res = odbc_primarykeys($db->connection, $db->dsn[username], $db->dsn[username], $table); $pk_all = array(); while ($data = odbc_fetch_array($res)) { $pk_all[] = $data[$key_name]; } $result = array(); foreach ($indexes as $index) { if (!in_array($index, $pk_all) && ($index = $this->_fixIndexName($index))) { $result[$index] = true; } } if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { $result = array_change_key_case($result, $db->options['field_case']); } return array_keys($result); }