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 :
"");
136 fPort = (fPort>0) ? fPort : 1521;
163 fEnv->terminateConnection(fConn);
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;
352 Int_t sqltype = kSQL_NONE;
354 if (data_type==
"NUMBER") {
355 sqltype = kSQL_NUMERIC;
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")) {
372 sqltype = kSQL_VARCHAR;
373 data_precision = char_col_decl_length;
377 if (data_type==
"FLOAT") {
378 sqltype = kSQL_FLOAT;
380 if (data_precision==126) data_precision = -1;
384 if (data_type==
"BINARY_FLOAT") {
385 sqltype = kSQL_FLOAT;
391 if (data_type==
"BINARY_DOUBLE") {
392 sqltype = kSQL_DOUBLE;
398 if (data_type==
"LONG") {
399 sqltype = kSQL_VARCHAR;
400 data_length = 0x7fffffff;
405 if (data_type.Contains(
"TIMESTAMP")) {
406 sqltype = kSQL_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());
548 if (fInfo.Length()>0) fInfo +=
"\n";
605 if (fmt==0) fmt =
"MM/DD/YYYY, HH24:MI:SS";
606 fgDatimeFormat = fmt;
614 return fgDatimeFormat;
TOracleServer(const char *db, const char *uid, const char *pw)
format for converting date and time stamps into string
Bool_t Commit()
Commits all changes made since the previous Commit() or Rollback() Return kTRUE if OK...
TList * GetTablesList(const char *wild=0)
Return list of user tables Parameter wild specifies wildcard for table names.
Collectable string class.
This class represents a WWW compatible URL.
const char * GetProtocol() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
#define CheckConnect(method, res)
TSQLTableInfo * GetTableInfo(const char *tablename)
Produces SQL table info Object must be deleted by user.
Bool_t Exec(const char *sql)
Execute sql command wich does not produce any result set.
virtual Bool_t StoreResult()=0
const char * GetOptions() const
virtual const char * GetString(Int_t)
Int_t Reload()
Reload permission tables.
const char * GetFile() const
Int_t DropDataBase(const char *dbname)
Drop (i.e.
const char * GetHost() const
void Close(Option_t *opt="")
Close connection to Oracle DB server.
virtual void EnableErrorOutput(Bool_t on=kTRUE)
void Info(const char *location, const char *msgfmt,...)
Int_t SelectDataBase(const char *dbname)
Select a database.
virtual Bool_t NextResultRow()=0
TSQLResult * GetTables(const char *dbname, const char *wild=0)
List all tables in the specified database.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)
List all columns in specified table in the specified database.
char * Form(const char *fmt,...)
virtual Int_t GetInt(Int_t)
Bool_t Rollback()
Drops all changes made since the previous Commit() or Rollback() Return kTRUE if OK.
~TOracleServer()
Close connection to Oracle DB server.
TSQLStatement * Statement(const char *sql, Int_t niter=100)
TSQLResult * Query(const char *sql)
Execute SQL command.
const char * ServerInfo()
Return Oracle server version info.
static const char * fgDatimeFormat
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, HH24:MI:SS"
virtual void Add(TObject *obj)
virtual Bool_t Process()=0
#define CatchError(method)
Int_t Shutdown()
Shutdown the database server.
static const char * GetDatimeFormat()
return value of actul convertion format from timestamps or date to string
TSQLResult * GetDataBases(const char *wild=0)
List all available databases.
Bool_t StartTransaction()
Call Commit() to submit all chanes, done before.
Int_t CreateDataBase(const char *dbname)
Create a database.