72#define CheckConnect(method, res) \
74 if (!IsConnected()) { \
75 SetError(-1,"Oracle database is not connected",method); \
80#define CatchError(method) \
81 catch (SQLException &oraex) { \
82 SetError(oraex.getErrorCode(), oraex.getMessage().c_str(), method); \
96 sword major_version(0), minor_version(0), update_num(0), patch_num(0), port_update_num(0);
97 OCIClientVersion(&major_version, &minor_version, &update_num, &patch_num, &port_update_num);
98 Info(
"TOracleServer",
"Oracle Call Interface version %u.%u.%u.%u.%u",
99 (
unsigned) major_version, (
unsigned) minor_version, (
unsigned) update_num, (
unsigned) patch_num, (
unsigned) port_update_num);
105 TString errmsg =
"Malformed db argument ";
113 SetError(-1,
"protocol in db argument should be oracle://",
"TOracleServer");
118 const char *conn_str = url.
GetFile();
120 if (*conn_str ==
'/') conn_str++;
128 fEnv = Environment::createEnvironment(Environment::OBJECT);
130 fEnv = Environment::createEnvironment();
132 fConn =
fEnv->createConnection(uid, pw, conn_str ? conn_str :
"");
167 Environment::terminateEnvironment(
fEnv);
180 SetError(-1,
"no query string specified",
"Statement");
185 oracle::occi::Statement *stmt =
fConn->createStatement(sql);
205 SetError(-1,
"no query string specified",
"Query");
210 oracle::occi::Statement *stmt =
fConn->createStatement();
219 stmt->setPrefetchRowCount(1000);
220 stmt->setPrefetchMemorySize(1000000);
239 SetError(-1,
"no query string specified",
"Exec");
243 oracle::occi::Statement *stmt =
nullptr;
248 stmt =
fConn->createStatement(sql);
254 fConn->terminateStatement(stmt);
277 TString sqlstr(
"SELECT object_name,owner FROM ALL_OBJECTS WHERE object_type='TABLE'");
278 if (dbname && dbname[0])
279 sqlstr = sqlstr +
" AND owner='" + dbname +
"'";
290 TString cmd(
"SELECT table_name FROM user_tables");
291 if ((wild!=0) && (*wild!=0))
292 cmd+=
Form(
" WHERE table_name LIKE '%s'", wild);
295 if (!stmt)
return nullptr;
297 TList *lst =
nullptr;
302 const char* tablename = stmt->
GetString(0);
303 if (!tablename)
continue;
325 if (!tablename || (*tablename==0))
return nullptr;
330 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());
333 if (!stmt)
return nullptr;
340 TList *lst =
nullptr;
345 const char* columnname = stmt->
GetString(0);
352 Int_t data_sign = -1;
356 if (data_type==
"NUMBER") {
358 if (data_precision<=0) {
367 if (data_type==
"CHAR") {
369 data_precision = char_col_decl_length;
373 if ((data_type==
"VARCHAR") || (data_type==
"VARCHAR2")) {
375 data_precision = char_col_decl_length;
379 if (data_type==
"FLOAT") {
382 if (data_precision==126) data_precision = -1;
386 if (data_type==
"BINARY_FLOAT") {
393 if (data_type==
"BINARY_DOUBLE") {
400 if (data_type==
"LONG") {
402 data_length = 0x7fffffff;
407 if (data_type.
Contains(
"TIMESTAMP")) {
414 IsNullable = (*nstr==
'Y') || (*nstr==
'y');
426 if (!lst) lst =
new TList;
456 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);
458 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());
607 if (fmt==0) fmt =
"MM/DD/YYYY, HH24:MI:SS";
#define CheckConnect(method, res)
#define CatchError(method)
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
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.
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