61using namespace oracle::occi;
67#define CheckConnect(method, res) \
69 if (!IsConnected()) { \
70 SetError(-1,"Oracle database is not connected",method); \
75#define CatchError(method) \
76 catch (SQLException &oraex) { \
77 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(), method); \
94 sword major_version(0), minor_version(0), update_num(0), patch_num(0), port_update_num(0);
95 OCIClientVersion(&major_version, &minor_version, &update_num, &patch_num, &port_update_num);
96 Info(
"TOracleServer",
"Oracle Call Interface version %u.%u.%u.%u.%u",
97 (
unsigned) major_version, (
unsigned) minor_version, (
unsigned) update_num, (
unsigned) patch_num, (
unsigned) port_update_num);
103 TString errmsg =
"Malformed db argument ";
105 SetError(-1, errmsg.Data(),
"TOracleServer");
111 SetError(-1,
"protocol in db argument should be oracle://",
"TOracleServer");
116 const char *conn_str = url.
GetFile();
118 if (*conn_str ==
'/') conn_str++;
123 Int_t pos = options.Index(
"ObjectMode");
126 fEnv = Environment::createEnvironment(Environment::OBJECT);
128 fEnv = Environment::createEnvironment();
130 fConn =
fEnv->createConnection(uid, pw, conn_str ? conn_str :
"");
165 Environment::terminateEnvironment(
fEnv);
178 SetError(-1,
"no query string specified",
"Statement");
183 oracle::occi::Statement *stmt =
fConn->createStatement(sql);
203 SetError(-1,
"no query string specified",
"Query");
208 oracle::occi::Statement *stmt =
fConn->createStatement();
217 stmt->setPrefetchRowCount(1000);
218 stmt->setPrefetchMemorySize(1000000);
237 SetError(-1,
"no query string specified",
"Exec");
241 oracle::occi::Statement *stmt = 0;
246 stmt =
fConn->createStatement(sql);
252 fConn->terminateStatement(stmt);
275 TString sqlstr(
"SELECT object_name,owner FROM ALL_OBJECTS WHERE object_type='TABLE'");
276 if (dbname && dbname[0])
277 sqlstr = sqlstr +
" AND owner='" + dbname +
"'";
279 return Query(sqlstr.Data());
288 TString cmd(
"SELECT table_name FROM user_tables");
289 if ((wild!=0) && (*wild!=0))
290 cmd+=
Form(
" WHERE table_name LIKE '%s'", wild);
293 if (stmt==0)
return 0;
300 const char* tablename = stmt->
GetString(0);
301 if (tablename==0)
continue;
323 if ((tablename==0) || (*tablename==0))
return 0;
325 TString
table(tablename);
328 sql.Form(
"SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, CHAR_COL_DECL_LENGTH FROM user_tab_columns WHERE table_name = '%s' ORDER BY COLUMN_ID",
table.Data());
331 if (stmt==0)
return 0;
343 const char* columnname = stmt->
GetString(0);
350 Int_t data_sign = -1;
354 if (data_type==
"NUMBER") {
356 if (data_precision<=0) {
365 if (data_type==
"CHAR") {
367 data_precision = char_col_decl_length;
371 if ((data_type==
"VARCHAR") || (data_type==
"VARCHAR2")) {
373 data_precision = char_col_decl_length;
377 if (data_type==
"FLOAT") {
380 if (data_precision==126) data_precision = -1;
384 if (data_type==
"BINARY_FLOAT") {
391 if (data_type==
"BINARY_DOUBLE") {
398 if (data_type==
"LONG") {
400 data_length = 0x7fffffff;
405 if (data_type.Contains(
"TIMESTAMP")) {
412 IsNullable = (*nstr==
'Y') || (*nstr==
'y');
424 if (lst==0) lst =
new TList;
451 TString
table(tablename);
454 sql.Form(
"select COLUMN_NAME, concat(concat(concat(data_type,'('),data_length),')') \"Type\" FROM user_tab_columns WHERE table_name like '%s' ORDER BY COLUMN_ID", wild);
456 sql.Form(
"select COLUMN_NAME, concat(concat(concat(data_type,'('),data_length),')') \"Type\" FROM user_tab_columns WHERE table_name = '%s' ORDER BY COLUMN_ID",
table.Data());
605 if (fmt==0) fmt =
"MM/DD/YYYY, HH24:MI:SS";
#define CatchError(method)
#define CheckConnect(method, res)
char * Form(const char *fmt,...)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual void Add(TObject *obj)
Collectable string class.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static void SetDatimeFormat(const char *fmt="MM/DD/YYYY, HH24:MI:SS")
set format for converting timestamps or date field into string default value is "MM/DD/YYYY,...
oracle::occi::Connection * fConn
Int_t Reload()
Reload permission tables.
TSQLStatement * Statement(const char *sql, Int_t niter=100)
TSQLResult * Query(const char *sql)
Execute SQL command.
TSQLTableInfo * GetTableInfo(const char *tablename)
Produces SQL table info Object must be deleted by user.
Int_t CreateDataBase(const char *dbname)
Create a database.
void Close(Option_t *opt="")
Close connection to Oracle DB server.
Bool_t Exec(const char *sql)
Execute sql command wich does not produce any result set.
static const char * fgDatimeFormat
~TOracleServer()
Close connection to Oracle DB server.
const char * ServerInfo()
Return Oracle server version info.
Int_t DropDataBase(const char *dbname)
Drop (i.e.
TSQLResult * GetTables(const char *dbname, const char *wild=0)
List all tables in the specified database.
TSQLResult * GetDataBases(const char *wild=0)
List all available databases.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)
List all columns in specified table in the specified database.
Bool_t StartTransaction()
Call Commit() to submit all chanes, done before.
static const char * GetDatimeFormat()
return value of actul convertion format from timestamps or date to string
oracle::occi::Environment * fEnv
Bool_t Commit()
Commits all changes made since the previous Commit() or Rollback() Return kTRUE if OK.
Int_t SelectDataBase(const char *dbname)
Select a database.
TOracleServer(const char *db, const char *uid, const char *pw)
format for converting date and time stamps into string
TList * GetTablesList(const char *wild=0)
Return list of user tables Parameter wild specifies wildcard for table names.
Bool_t IsConnected() const
Int_t Shutdown()
Shutdown the database server.
Bool_t Rollback()
Drops all changes made since the previous Commit() or Rollback() Return kTRUE if OK.
void ClearError()
reset error fields
void SetError(Int_t code, const char *msg, const char *method=0)
set new values for error fields if method is specified, displays error message
virtual void EnableErrorOutput(Bool_t on=kTRUE)
virtual const char * GetString(Int_t)
virtual Bool_t NextResultRow()=0
virtual Int_t GetInt(Int_t)
virtual Bool_t Process()=0
virtual Bool_t StoreResult()=0
This class represents a WWW compatible URL.
const char * GetFile() const
const char * GetHost() const
const char * GetOptions() const
const char * GetProtocol() const