37 Error(
"TSapDBServer",
"malformed db argument %s", db);
43 Error(
"TSapDBServer",
"protocol in db argument should be sapdb it is %s",
49 const char *dbase = url.
GetFile();
52 RETCODE rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &fEnv);
53 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
54 Error(
"TSapDBServer",
"allocation of environment failed");
59 rc = SQLAllocHandle(SQL_HANDLE_DBC, fEnv, &fSapDB);
60 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
61 printSQLError(fSapDB, SQL_NULL_HSTMT);
62 Error(
"TSapDBServer",
"allocation of db failed");
68 const char *dbnam =
Form(
"%s:%s", url.
GetHost(), dbase);
69 rc = SQLConnect(fSapDB, (SQLCHAR*) dbnam, SQL_NTS,
70 (SQLCHAR*) uid, SQL_NTS, (SQLCHAR*) pw, SQL_NTS);
72 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
73 printSQLError(fSapDB, SQL_NULL_HSTMT);
74 Error(
"TSapDBServer",
"connection to %s:%s failed", url.
GetHost(), dbase);
79 rc = SQLAllocHandle(SQL_HANDLE_STMT, fSapDB, &fStmt);
80 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
81 printSQLError(fSapDB, fStmt);
82 Error(
"TSapDBServer",
"allocation of statement handle failed");
86 rc = SQLAllocHandle(SQL_HANDLE_STMT, fSapDB, &fStmtCnt);
87 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
88 printSQLError(fSapDB, fStmtCnt);
89 Error(
"TSapDBServer",
"allocation of count statement handle failed");
115 RETCODE rc = SQLDisconnect(
fSapDB);
116 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
118 Error(
"TSapDBServer",
"disconnect during close failed");
121 rc = SQLFreeHandle(SQL_HANDLE_STMT,
fStmt);
122 if (rc != SQL_SUCCESS) {
126 rc = SQLFreeHandle(SQL_HANDLE_STMT,
fStmtCnt);
127 if (rc != SQL_SUCCESS) {
131 rc = SQLFreeHandle(SQL_HANDLE_DBC,
fSapDB);
132 if (rc != SQL_SUCCESS) {
134 Error(
"TSapDBServer",
"free database handle during close failed");
137 rc = SQLFreeHandle(SQL_HANDLE_ENV,
fEnv);
138 if (rc != SQL_SUCCESS) {
139 Error(
"TSapDBServer",
"free environment handle during close failed");
153 Error(
"Query",
"not connected");
157 RETCODE rc = SQLFreeHandle(SQL_HANDLE_STMT,
fStmt);
158 if (rc != SQL_SUCCESS) {
160 Error(
"TSapDBServer",
"free statement handle failed");
163 rc = SQLAllocHandle(SQL_HANDLE_STMT,
fSapDB, &
fStmt);
164 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
166 Error(
"TSapDBServer",
"allocation statement handle failed");
169 rc = SQLFreeHandle(SQL_HANDLE_STMT,
fStmtCnt);
170 if (rc != SQL_SUCCESS) {
172 Error(
"TSapDBServer",
"free count statement handle failed");
176 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
178 Error(
"TSapDBServer",
"allocation count statement handle failed");
182 TString sqlcnt =
"SELECT COUNT(*) ";
189 sqlcnt += sqlt(i, sqlt.
Length());
191 if (SQLExecDirect(
fStmtCnt, (SQLCHAR*)sqlcnt.
Data(), SQL_NTS) !=
197 SQLBindCol(
fStmtCnt, 1, SQL_C_LONG, &slRowCount, 0, 0);
203 if (SQLPrepare(
fStmt, (SQLCHAR*)sqlt.
Data(), SQL_NTS) != SQL_SUCCESS) {
208 if (SQLExecute(
fStmt) != SQL_SUCCESS) {
212 if (SQLEndTran(SQL_HANDLE_DBC,
fSapDB, SQL_COMMIT) != SQL_SUCCESS) {
227 Error(
"SelectDataBase",
"not connected");
232 Error(
"SelectDataBase",
"no such database");
250 Error(
"GetDataBases",
"not connected");
266 Error(
"GetTables",
"not connected");
270 TString sql =
"SELECT TABLENAME FROM TABLES";
272 sql +=
Form(
" WHERE TABLENAME LIKE '%s'", wild);
287 Error(
"GetColumns",
"not connected");
292 Error(
"GetColumns",
"no such database %s", dbname);
298 sql =
Form(
"SELECT COLUMNNAME FROM COLUMNS WHERE TABLENAME LIKE '%s' AND COLUMNNAME LIKE '%s'", table, wild);
300 sql =
Form(
"SELECT COLUMNNAME FROM COLUMNS WHERE TABLENAME LIKE '%s'", table);
312 Error(
"CreateDataBase",
"not connected");
316 Error(
"CreateDataBase",
"not implemented");
328 Error(
"DropDataBase",
"not connected");
332 Error(
"DropDataBase",
"not implemented");
344 Error(
"Reload",
"not connected");
348 Error(
"Reload",
"not implemented");
360 Error(
"Shutdown",
"not connected");
364 Error(
"Shutdown",
"not implemented");
374 Error(
"ServerInfo",
"not connected");
378 TString sql =
"SELECT KERNEL,RUNTIMEENVIRONMENT FROM DOMAIN.VERSIONS";
388 row_info = res_info->
Next();
404 UCHAR errortxt[512+1];
407 SQLError(SQL_NULL_HENV, hdbc, hstmt, sqlstate, &sqlcode, errortxt,
410 printf (
"SQL state: %s\n", sqlstate);
411 printf (
"SQL code: %ld\n",
long(sqlcode));
412 printf (
"SQL Errortext:\n%s\n\n", errortxt);
const char * GetHost() const
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)
List all columns in specified table in the specified database.
TSQLResult * GetDataBases(const char *wild=0)
List all available databases.
This class represents a WWW compatible URL.
const char * GetProtocol() const
const char * ServerInfo()
Return server info.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
const char * Data() const
Int_t Reload()
Reload permission tables.
ClassImp(TSapDBServer) TSapDBServer
Open a connection to a SapDB DB server.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Error(const char *location, const char *msgfmt,...)
virtual Bool_t IsConnected() const
char * Form(const char *fmt,...)
virtual const char * GetField(Int_t field)=0
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Int_t SelectDataBase(const char *dbname)
Select a database.
void Close(Option_t *opt="")
Close connection to SapDB DB server.
Int_t CreateDataBase(const char *dbname)
Create a database.
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 * Query(const char *sql)
Execute SQL command.
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Int_t Shutdown()
Shutdown the database server.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
const char * GetFile() const
~TSapDBServer()
Close connection to SapDB DB server.
static Int_t printSQLError(SQLHDBC hdbc, SQLHSTMT hstmt)
Print SapDB error message.
virtual TSQLRow * Next()=0