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); \
91 sword major_version(0), minor_version(0), update_num(0), patch_num(0), port_update_num(0);
92 OCIClientVersion(&major_version, &minor_version, &update_num, &patch_num, &port_update_num);
93 Info(
"TOracleServer",
"Oracle Call Interface version %u.%u.%u.%u.%u",
94 (
unsigned) major_version, (
unsigned) minor_version, (
unsigned) update_num, (
unsigned) patch_num, (
unsigned) port_update_num);
100 TString errmsg =
"Malformed db argument ";
108 SetError(-1,
"protocol in db argument should be oracle://",
"TOracleServer");
113 const char *conn_str = url.
GetFile();
115 if (*conn_str ==
'/') conn_str++;
123 fEnv = Environment::createEnvironment(Environment::OBJECT);
125 fEnv = Environment::createEnvironment();
127 fConn =
fEnv->createConnection(uid, pw, conn_str ? conn_str :
"");
162 Environment::terminateEnvironment(
fEnv);
175 SetError(-1,
"no query string specified",
"Statement");
180 oracle::occi::Statement *stmt =
fConn->createStatement(sql);
200 SetError(-1,
"no query string specified",
"Query");
205 oracle::occi::Statement *stmt =
fConn->createStatement();
214 stmt->setPrefetchRowCount(1000);
215 stmt->setPrefetchMemorySize(1000000);
234 SetError(-1,
"no query string specified",
"Exec");
238 oracle::occi::Statement *stmt =
nullptr;
243 stmt =
fConn->createStatement(sql);
249 fConn->terminateStatement(stmt);
272 TString sqlstr(
"SELECT object_name,owner FROM ALL_OBJECTS WHERE object_type='TABLE'");
273 if (dbname && dbname[0])
274 sqlstr = sqlstr +
" AND owner='" + dbname +
"'";
285 TString cmd(
"SELECT table_name FROM user_tables");
286 if ((wild!=0) && (*wild!=0))
287 cmd+=
Form(
" WHERE table_name LIKE '%s'", wild);
290 if (!stmt)
return nullptr;
292 TList *lst =
nullptr;
297 const char* tablename = stmt->
GetString(0);
298 if (!tablename)
continue;
320 if (!tablename || (*tablename==0))
return nullptr;
325 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());
328 if (!stmt)
return nullptr;
335 TList *lst =
nullptr;
340 const char* columnname = stmt->
GetString(0);
347 Int_t data_sign = -1;
351 if (data_type==
"NUMBER") {
353 if (data_precision<=0) {
362 if (data_type==
"CHAR") {
364 data_precision = char_col_decl_length;
368 if ((data_type==
"VARCHAR") || (data_type==
"VARCHAR2")) {
370 data_precision = char_col_decl_length;
374 if (data_type==
"FLOAT") {
377 if (data_precision==126) data_precision = -1;
381 if (data_type==
"BINARY_FLOAT") {
388 if (data_type==
"BINARY_DOUBLE") {
395 if (data_type==
"LONG") {
397 data_length = 0x7fffffff;
402 if (data_type.
Contains(
"TIMESTAMP")) {
409 IsNullable = (*nstr==
'Y') || (*nstr==
'y');
421 if (!lst) lst =
new TList;
451 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);
453 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());
602 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
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 actul convertion format from timestamps or date to string
oracle::occi::Environment * fEnv
TOracleServer(const char *db, const char *uid, const char *pw)
format for converting date and time stamps into string
Bool_t IsConnected() const final
Int_t Reload() final
Reload permission tables.
Int_t SelectDataBase(const char *dbname) final
Select a database.
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.
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