Skip to content
Snippets Groups Projects
Commit 3638a827 authored by Rene Brun's avatar Rene Brun
Browse files

From Yan Liu:

1. implemented TOracleServer::GetColumns() using occi
MetaData instead of original SQL select statement. This
implementation works for any Oracle 10 databases without
constraints on user granted priveleges.

2. implemented TOracleServer::GetTables(). The TSQLServer::GetTables()
is MySQL oriented. In Oracle, table is accessed in "schema.table" format.
The implementation handles two cases: with and without schema name.
The return value conforms TSQL spec, i.e. a TSQLResult pointer.

3. fixed a critical bug in TOracleResult::Next().


git-svn-id: http://root.cern.ch/svn/root/trunk@11214 27541ba8-7e3a-0410-8455-c3a389f83636
parent 7cee32e2
No related branches found
No related tags found
No related merge requests found
// @(#)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="");
......
// @(#)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;
}
// @(#)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);
}
//______________________________________________________________________________
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment