diff --git a/oracle/inc/TOracleResult.h b/oracle/inc/TOracleResult.h index 4844a62a42806d7f0b302a478c39c78ba26cddd0..b9e06d1a05ff14956c2c7ca6a6658a93f4765f75 100644 --- a/oracle/inc/TOracleResult.h +++ b/oracle/inc/TOracleResult.h @@ -1,4 +1,4 @@ -// @(#)root/physics:$Name: v4-00-08 $:$Id: TOracleResult.h,v 1.0 2004/12/04 17:00:45 rdm Exp $ +// @(#)root/physics:$Name: $:$Id: TOracleResult.h,v 1.1 2005/02/28 19:11:00 rdm Exp $ // Author: Yan Liu and Shaowen Wang 23/11/04 /************************************************************************* @@ -32,6 +32,7 @@ using namespace oracle::occi; namespace std { using vector: }*/ +class Connection; class Statement; class ResultSet; class MetaData; @@ -53,6 +54,7 @@ private: public: TOracleResult(Statement *stmt); + TOracleResult(Connection *conn, const char *tableName); ~TOracleResult(); void Close(Option_t *opt=""); diff --git a/oracle/src/TOracleResult.cxx b/oracle/src/TOracleResult.cxx index bff5fc76a2148327ab2f53ab57901c765021c8ef..f921a692b849c8668e31502101b39f3257df5a35 100644 --- a/oracle/src/TOracleResult.cxx +++ b/oracle/src/TOracleResult.cxx @@ -1,4 +1,4 @@ -// @(#)root/oracle:$Name: v4-00-08 $:$Id: TOracleResult.cxx,v 1.0 2004/12/04 17:00:45 rdm Exp $ +// @(#)root/oracle:$Name: $:$Id: TOracleResult.cxx,v 1.1 2005/02/28 19:11:00 rdm Exp $ // Author: Yan Liu and Shaowen Wang 23/11/04 /************************************************************************* @@ -42,7 +42,7 @@ TOracleResult::TOracleResult(Statement *stmt) fResult = stmt->getResultSet(); GetMetaDataInfo(); fUpdateCount = 0; - printf("type:%d columnsize:%d \n", fResultType, fFieldCount); + //printf("type:%d columnsize:%d \n", fResultType, fFieldCount); } else if (stmt->status() == Statement::UPDATE_COUNT_AVAILABLE) { fResultType = 0; fResult = 0; @@ -56,6 +56,24 @@ TOracleResult::TOracleResult(Statement *stmt) } } +//______________________________________________________________________________ +//This construction func is only used to get table metainfo +TOracleResult::TOracleResult(Connection *conn, const char *tableName) +{ + if (!tableName || !conn) { + Error("TOracleResult", "construction: empty input parameter"); + fResultType = -1; + } else { + MetaData connMD = conn->getMetaData(tableName, MetaData::PTYPE_TABLE); + fFieldInfo = new vector<MetaData>(connMD.getVector(MetaData::ATTR_LIST_COLUMNS)); + fFieldCount = fFieldInfo->size(); + fRowCount = 0; + fResult = 0; + fUpdateCount = 0; + fResultType = 1; + } +} + //______________________________________________________________________________ TOracleResult::~TOracleResult() { @@ -83,11 +101,7 @@ void TOracleResult::Close(Option_t *) Bool_t TOracleResult::IsValid(Int_t field) { // Check if result set is open and field index within range. - - if (!fResult) { - Error("IsValid", "result set closed"); - return kFALSE; - } + if (field < 0 || field >= fFieldCount) { Error("IsValid", "field index out of bounds"); return kFALSE; @@ -99,11 +113,12 @@ Bool_t TOracleResult::IsValid(Int_t field) Int_t TOracleResult::GetFieldCount() { // Get number of fields in result. - + /* if (!fResult) { Error("GetFieldCount", "result set closed"); return 0; } + */ return fFieldCount; } @@ -134,6 +149,8 @@ TSQLRow *TOracleResult::Next() return new TOracleRow(fUpdateCount); } // if select query, - fResult->next(); - return new TOracleRow(fResult, fFieldInfo); + if (fResult->next()) + return new TOracleRow(fResult, fFieldInfo); + else + return 0; } diff --git a/oracle/src/TOracleServer.cxx b/oracle/src/TOracleServer.cxx index 8422a2cd47005eeaddf81b0eb57e854f55c5734b..423fcd1ab4aea9aa57d373fc871103f15db70903 100644 --- a/oracle/src/TOracleServer.cxx +++ b/oracle/src/TOracleServer.cxx @@ -1,4 +1,4 @@ -// @(#)root/oracle:$Name: v4-00-08 $:$Id: TOracleServer.cxx,v 1.0 2004/12/04 17:00:45 rdm Exp $ +// @(#)root/oracle:$Name: $:$Id: TOracleServer.cxx,v 1.1 2005/02/28 19:11:00 rdm Exp $ // Author: Yan Liu and Shaowen Wang 23/11/04 /************************************************************************* @@ -47,13 +47,6 @@ TOracleServer::TOracleServer(const char *db, const char *uid, const char *pw) if (strcmp(url.GetFile(), "/")) conn_str = url.GetFile()+1; - if (conn_str == 0) { - Error("TOracleServer", "Host name or database name missing in url %s", - url.GetUrl()); - MakeZombie(); - return; - } - try { fEnv = Environment::createEnvironment(); fConn = fEnv->createConnection(uid, pw, conn_str); @@ -132,28 +125,26 @@ TSQLResult *TOracleServer::GetTables(const char *dbname, const char *wild) // Returns a pointer to a TSQLResult object if successful, 0 otherwise. // The result object must be deleted by the user. - // user must be granted priveledge to query object "sys" +/* In Oracle 9 and above, table is accessed in schema.table format. + * GetTables returns tables in all schemas accessible for the user. + * Assumption: table ALL_OBJECTS is accessible for the user, which is true in Oracle 10g + * The returned TSQLResult has two columns: schema_name, table_name + * "dbname": if specified, return table list of this schema, or return all tables + * "wild" is not used in this implementation +*/ if (!IsConnected()) { Error("GetTables", "not connected"); return 0; } - - if (SelectDataBase(dbname) != 0) { - Error("GetTables", "no such database %s", dbname); - return 0; - } + TString sqlstr("SELECT owner, object_name FROM ALL_OBJECTS WHERE object_type='TABLE'"); + if (dbname) + sqlstr = sqlstr + " AND owner='" + dbname + "'"; TSQLResult *tabRs; - if (wild) - { - char sql[256]; - sprintf(sql, "select TABLE_NAME FROM sys.user_tables where TABLE_NAME LIKE %s", wild); - tabRs = Query(sql); - } - else - tabRs = Query("select TABLE_NAME FROM sys.user_tables"); + tabRs = Query(sqlstr.Data()); return tabRs; + } //______________________________________________________________________________ @@ -165,12 +156,6 @@ TSQLResult *TOracleServer::GetColumns(const char *dbname, const char *table, // Returns a pointer to a TSQLResult object if successful, 0 otherwise. // The result object must be deleted by the user. - // user must be granted priveledge to query object "sys" - // TODO: to take adv of OCCI, should use MetaData to get column names - // + conn->getMetaData(table, MetaData::PTYPE_TABLE) - // + getVector(ATTR_LIST_COLUMNS) - // + getString(ATTR_NAME) - if (!IsConnected()) { Error("GetColumns", "not connected"); return 0; @@ -180,15 +165,8 @@ TSQLResult *TOracleServer::GetColumns(const char *dbname, const char *table, Error("GetColumns", "no such database %s", dbname); return 0; } - - char sql[256]; - if (wild) { - sprintf(sql, "select column_name from sys.user_tab_columns where (table_name=%s) AND (column_name like %s)", table, wild); - } else { - sprintf(sql, "select column_name from sys.user_tab_columns where table_name=%s",table); - } - TSQLResult *tabRs = Query(sql); - return tabRs; + return new TOracleResult(fConn, table); + } //______________________________________________________________________________