oracle资料库函式库"T.char_col_decl_length,I.index_name". " FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I". " WHERE T.column_name=I.column_name (+)". " AND T.table_name=I.table_name (+)". " AND T.table_name=UPPER('$table') ORDER BY T.column_id"); $i=0; while ($this->next_record()) { $res[$i]["table"] = $this->Record[table_name]; $res[$i]["name"] = strtolower($this->Record[column_name]); $res[$i]["type"] = $this->Record[data_type]; $res[$i]["len"] = $this->Record[data_length]; if ($this->Record[index_name]) $res[$i]["flags"] = "INDEX "; $res[$i]["flags"] .= ( $this->Record[nullable] == 'N') ? '' : 'NOT NULL'; $res[$i]["format"]= (int)$this->Record[data_precision].",". (int)$this->Record[data_scale]; if ("0,0"==$res[$i]["format"]) $res[$i]["format"]=''; $res[$i]["index"] = $this->Record[index_name]; $res[$i]["chars"] = $this->Record[char_col_decl_length]; if ($full) { $j=$res[$i]["name"]; $res["meta"][$j] = $i; $res["meta"][strtoupper($j)] = $i; switch ($res[$i]["type"]) { case "VARCHAR2" : case "VARCHAR" : case "CHAR" : $res["php_type"]="string"; $res["php_subtype"]=""; break; case "DATE" : $res["php_type"]="string"; $res["php_subtype"]="date"; break; case "BLOB" : case "CLOB" : case "BFILE" : case "RAW" : case "LONG" : case "LONG RAW" : $res["php_type"]="string"; $res["php_subtype"]="blob"; break; case "NUMBER" : if ($res[$i]["format"]) { $res["php_type"]="double"; $res["php_subtype"]=""; } else { $res["php_type"]="int"; $res["php_subtype"]=""; } break; default : $this->halt("metadata(): Type is not a valid value: '$res[$i][type]'"); break; } } if ($full) $res["meta"][$res[$i]["name"]] = $i; $i++; } if ($full) $res["num_fields"]=$i; # $this->disconnect(); return $res; } ## THIS FUNCTION IS UNSTESTED! function affected_rows() { if ($this->Debug) echo "<BR>Debug: affected_rows=". ora_numrows($this->Query_ID)."<BR>"; return ora_numrows($this->Query_ID); } ## Known bugs: It will not work for SELECT DISTINCT and any ## other constructs which are depending on the resulting rows. ## So you *really need* to check every query you make, if it ## will work with it! ## ## Also, for a qualified replacement you need to parse the ## selection, cause this will fail: "SELECT id, from FROM ..."). ## "from" is - as far as I know a keyword in Oracle, so it can ## only be used in this way. But you have been warned. function num_rows() { $curs=ora_open($this->Link_ID); ## this is the important part and it is also the HACK! if (eregi("^[[:space:]]*SELECT[[:space:]]",$this->lastQuery) ) { # This works for all?? cases, including SELECT DISTINCT case. # We just make select count(*) from original sql expression # and remove ORDER BY (if any) for speed # I like regular expressions too ;-))) $q = sprintf("SELECT COUNT(*) FROM (%s)", @eregi_Replace("ORDER[[:space:]]+BY[^)]*()*)", "\1", $this->lastQuery) ); # works also for subselects: # if (eregi("[[:space:]]+FROM([[:space:]]+.*[[:space:]]+FROM)",$this->lastQuery,$r)) # $areplace=$r[1]; # $q=eregi_Replace("^[[:space:]]*SELECT[[:space:]]+". # ".*[[:space:]]+FROM", # "SELECT COUNT(*) FROM$areplace", # $this->lastQuery); if ($this->Debug) echo "<BR>Debug: num_rows: $q<BR>"; ORA_parse($curs,$q); ORA_exec($curs); ORA_fetch($curs); $result = ORA_getcolumn($curs,0); ORA_close($curs); if ($this->Debug) { echo "<BR>Debug: ID ".$this->QueryID. " num_rows=". $result ."<BR>"; } return $result; } else { $this->halt("Last Query was not a SELECT: $this->lastQuery"); } } function num_fields() { if ($this->Debug) echo "<BR>Debug: num_fields=". ora_numcols($this->Query_ID) . "<BR>"; 上一篇:一个用于网络的工具函数库 下一篇:PHP聊天室技术 更多相关文章
|
推荐文章
精彩文章
|