70#define CheckConnect(method, res) \
72 if (!IsConnected()) { \
73 SetError(-1,"Oracle database is not connected",method); \
78#define CatchError(method) \
79 catch (oracle::occi::SQLException &oraex) { \
80 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 ";
111 SetError(-1,
"protocol in db argument should be oracle://",
"TOracleServer");
116 const char *conn_str = url.
GetFile();
118 if (*conn_str ==
'/') conn_str++;
126 fEnv = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::OBJECT);
128 fEnv = oracle::occi::Environment::createEnvironment();
130 fConn =
fEnv->createConnection(uid, pw, conn_str ? conn_str :
"");
164 oracle::occi::Environment::terminateEnvironment(
fEnv);
177 SetError(-1,
"no query string specified",
"Statement");
182 oracle::occi::Statement *stmt =
fConn->createStatement(sql);
184 oracle::occi::Blob parblob(
fConn);
202 SetError(-1,
"no query string specified",
"Query");
207 oracle::occi::Statement *stmt =
fConn->createStatement();
216 stmt->setPrefetchRowCount(1000);
217 stmt->setPrefetchMemorySize(1000000);
236 SetError(-1,
"no query string specified",
"Exec");
240 oracle::occi::Statement *stmt =
nullptr;
245 stmt =
fConn->createStatement(sql);
251 fConn->terminateStatement(stmt);
274 TString sqlstr(
"SELECT object_name,owner FROM ALL_OBJECTS WHERE object_type='TABLE'");
275 if (dbname && dbname[0])
276 sqlstr = sqlstr +
" AND owner='" + dbname +
"'";
287 TString cmd(
"SELECT table_name FROM user_tables");
292 if (!stmt)
return nullptr;
294 TList *lst =
nullptr;
299 const char* tablename = stmt->
GetString(0);
300 if (!tablename)
continue;
322 if (!tablename || (*tablename==0))
return nullptr;
327 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());
330 if (!stmt)
return nullptr;
337 TList *lst =
nullptr;
342 const char* columnname = stmt->
GetString(0);
349 Int_t data_sign = -1;
353 if (data_type==
"NUMBER") {
355 if (data_precision<=0) {
364 if (data_type==
"CHAR") {
366 data_precision = char_col_decl_length;
370 if ((data_type==
"VARCHAR") || (data_type==
"VARCHAR2")) {
372 data_precision = char_col_decl_length;
376 if (data_type==
"FLOAT") {
379 if (data_precision==126) data_precision = -1;
383 if (data_type==
"BINARY_FLOAT") {
390 if (data_type==
"BINARY_DOUBLE") {
397 if (data_type==
"LONG") {
399 data_length = 0x7fffffff;
404 if (data_type.
Contains(
"TIMESTAMP")) {
411 IsNullable = (*nstr==
'Y') || (*nstr==
'y');
423 if (!lst) lst =
new TList;
453 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);
455 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());
604 if (!fmt) fmt =
"MM/DD/YYYY, HH24:MI:SS";
#define CheckConnect(method, res)
#define CatchError(method)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void Add(TObject *obj) override
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
TSQLResult * GetTables(const char *dbname, const char *wild=nullptr) final
List all tables in the specified database.
Int_t DropDataBase(const char *dbname) final
Drop (i.e.
Int_t Shutdown() final
Shutdown the database server.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr) final
List all columns in specified table in the specified database.
static const char * fgDatimeFormat
TSQLStatement * Statement(const char *sql, Int_t niter=100) final
Bool_t StartTransaction() final
Call Commit() to submit all chanes, done before.
~TOracleServer()
Close connection to Oracle DB server.
Bool_t Commit() final
Commits all changes made since the previous Commit() or Rollback() Return kTRUE if OK.
void Close(Option_t *opt="") final
Close connection to Oracle DB server.
Bool_t Rollback() final
Drops all changes made since the previous Commit() or Rollback() Return kTRUE if OK.
const char * ServerInfo() final
Return Oracle server version info.
TSQLResult * Query(const char *sql) final
Execute SQL command.
Bool_t Exec(const char *sql) final
Execute sql command which does not produce any result set.
TList * GetTablesList(const char *wild=nullptr) final
Return list of user tables Parameter wild specifies wildcard for table names.
TSQLTableInfo * GetTableInfo(const char *tablename) final
Produces SQL table info Object must be deleted by user.
Int_t CreateDataBase(const char *dbname) final
Create a database.
TSQLResult * GetDataBases(const char *wild=nullptr) final
List all available databases.
static const char * GetDatimeFormat()
return value of actual conversion format from timestamps or date to string
oracle::occi::Environment * fEnv
Bool_t IsConnected() const final
Int_t Reload() final
Reload permission tables.
Int_t SelectDataBase(const char *dbname) final
Select a database.
TOracleServer(const TOracleServer &)=delete
format for converting date and time stamps into string
void ClearError()
reset error fields
void SetError(Int_t code, const char *msg, const char *method=nullptr)
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
const char * Data() const
void ToUpper()
Change string to upper case.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
This class represents a WWW compatible URL.
const char * GetFile() const
const char * GetHost() const
const char * GetOptions() const
const char * GetProtocol() const