int GdbiCommands::desc_slct( int sqlid, /* Index into ptrs to Oracle work areas */ int pos, /* position within select clause */ int name_len, /* The maximum size of name */ wchar_t *name, /* Name of this field */ int *rdbi_type, /* rdbi constant */ int *binary_size, /* bytes of memory to store the field */ int *null_ok ) { CheckDB(); int rc; if( this->SupportsUnicode() ) rc = ::rdbi_desc_slctW(m_pRdbiContext, sqlid, pos, name_len, name, rdbi_type, binary_size, null_ok ); else { char colName[GDBI_COLUMN_SIZE]; rc = ::rdbi_desc_slct(m_pRdbiContext, sqlid, pos, name_len, colName, rdbi_type, binary_size, null_ok ); wcsncpy(name,(const wchar_t*)FdoStringP( colName ), name_len ); name[name_len-1]='\0'; } if( rc == RDBI_SUCCESS || rc == RDBI_NOT_IN_DESC_LIST ) return rc; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
int GdbiCommands::bind( int cursorId, /* index into cursor array */ char *name, /* column/expression position */ int datatype, /* A data type from Inc/rdbi.h */ int size, /* binary size */ char *address, /* data address */ GDBI_NI_TYPE *null_ind, int typeBind ) { int loc_datatype = datatype; int loc_size = size; char *loc_address = address; CheckDB(); if( datatype == RDBI_WSTRING && ! SupportsUnicode() ) { throw new GdbiException(L"Cannot bind widechar strings; target RDBMS does not support widechar strings"); } if( ::rdbi_bind(m_pRdbiContext, cursorId, name, loc_datatype, loc_size, loc_address, (void *)null_ind, typeBind) == RDBI_SUCCESS ) return RDBI_SUCCESS; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
int GdbiCommands::tran_end( char *tran_id ) { CheckDB(); if( ::rdbi_tran_end( m_pRdbiContext, tran_id ) ) return RDBI_SUCCESS; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
int GdbiCommands::execute( int qid, int count, int offset ) { CheckDB(); int rc = ::rdbi_execute (m_pRdbiContext, qid, count, offset); if( rc == RDBI_SUCCESS ) return rc; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
int GdbiCommands::fetch( int sqlid, int count, int *rows_processed ) { CheckDB(); int rc = ::rdbi_fetch( m_pRdbiContext, sqlid, count, rows_processed ); if( rc == RDBI_SUCCESS || rc == RDBI_END_OF_FETCH ) return rc; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
int GdbiCommands::end_select( int sqlid ) { if( m_pRdbiContext == NULL ) return RDBI_SUCCESS; // This is called by a cleanup code invoked after the connection is closed CheckDB(); if( ::rdbi_end_select( m_pRdbiContext, sqlid ) == RDBI_SUCCESS ) return RDBI_SUCCESS; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
logical ServerConnection :: CheckDB (SC_Database *sc_database, CheckOptions check_opts, char *source, CSInstanceList *result, int32 wait_sec ) { DictionaryHandle dict; char cpath[513]; logical term = NO; strncpy(cpath,sc_database->DatabaseHandle::GetPath(),sizeof(cpath)-1); dict = sc_database->DatabaseHandle::GetDictionary(); sc_database->SetDBOHdl(NULL); sc_database->DatabaseHdl::Close(); term = CheckDB(dict,cpath,check_opts,source,result,wait_sec); return(term); }
int GdbiCommands::sp_release(FdoStringP sp) { CheckDB(); int rc = RDBI_GENERIC_ERROR; if(SupportsUnicode()) rc = ::rdbi_tran_spW (m_pRdbiContext, RDBI_SP_RL, sp); else rc = ::rdbi_tran_sp (m_pRdbiContext, RDBI_SP_RL, sp); if(rc == RDBI_SUCCESS || rc == RDBI_SP_NOT_SUPPORTED) return rc; ThrowException(); return RDBI_GENERIC_ERROR; }
int GdbiCommands::sp_rollback(FdoStringP sp) { CheckDB(); int rc = RDBI_GENERIC_ERROR; if(SupportsUnicode()) rc = ::rdbi_tran_spW (m_pRdbiContext, RDBI_SP_RB, sp); else rc = ::rdbi_tran_sp (m_pRdbiContext, RDBI_SP_RB, sp); if(rc == RDBI_SUCCESS) return rc; ThrowException(); return RDBI_GENERIC_ERROR; }
int GdbiCommands::run_sql( FdoStringP sql, bool isDDL, int *rows_processed ) { CheckDB(); int rc = RDBI_GENERIC_ERROR; if( SupportsUnicode() ) rc = ::rdbi_run_sqlW (m_pRdbiContext, sql, isDDL ? 1 : 0, rows_processed ); else rc = ::rdbi_run_sql (m_pRdbiContext, sql, isDDL ? 1 : 0, rows_processed ); if( rc == RDBI_SUCCESS ) return rc; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
int GdbiCommands::define( int sqlid, /* index into cursor array */ char *name, /* column/expression position */ int datatype, /* A data type from Inc/rdbi.h */ int size, /* binary size */ char *address, /* data address */ GDBI_NI_TYPE *null_ind /* pointer to null indicator variables */ ) { CheckDB(); if( ::rdbi_define(m_pRdbiContext, sqlid, name, datatype, size, address, (void *)null_ind ) == RDBI_SUCCESS ) return RDBI_SUCCESS; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
// In case sequence is not supported this method simulate a sequence allocation scheme. FdoInt64 GdbiCommands::NextRDBMSAutoincrementNumber( FdoString* adbSequenceName ) { FdoStringP tableName; FdoInt64 number = 0; bool seqSupported = true; CheckDB(); // Get the table name from the sequence name. if ( wcscmp( adbSequenceName, ADB_CLASSSEQW ) == 0 ) tableName = ADB_CLASSDEF_TABW; else if ( wcscmp( adbSequenceName, ADB_PLANSEQW ) == 0 ) tableName = ADB_SPATIAL_CONTEXT_TABLEW; else if ( wcscmp( adbSequenceName, ADB_PLANGROUPSEQW ) == 0 ) tableName = ADB_SPATIAL_CONTEXT_GROUP_TABLEW; else if ( wcscmp( adbSequenceName, ADB_FEATURESEQW ) == 0 ) tableName = L""; else seqSupported = false; if ( !seqSupported ) { // Should not happen since we handle all known SEQ cases ThrowException(); } else { if (SupportsUnicode()) { if ( ::rdbi_get_gen_idW ( m_pRdbiContext, tableName, &number ) != RDBI_SUCCESS ) ThrowException(); } else { if ( ::rdbi_get_gen_id ( m_pRdbiContext, tableName, &number ) != RDBI_SUCCESS ) ThrowException(); } // Note: The number is the current generated one. } return number; }
/** Message Queuing. * * @param szId Sensor ID * @param nMessageId 사용자 정의 Message ID * @param nMessageType Message Type (0x01 Immediately, 0x02 Lazy, 0x03 Passive) * @param nDuration Lazy, Passive 일 경우 유지 시간(sec) * @param nErrorHandler Error Handler * @param nPreHandler Pre-Action Handler * @param nPostHandler Post-Action Handler * @param nUserData User Data * @param nDataLength Message length * @param pszData Message * */ BOOL CMessageHelper::Add(const char *szId, UINT nMessageId, BYTE nMessageType, UINT nDuration, UINT nErrorHandler, UINT nPreHandler, UINT nPostHandler, UINT nUserData, int nDataLength, const BYTE *pszData) { int i=1; if(!CheckDB()) return FALSE; if(!Open()) return FALSE; try { CppSQLite3Statement stmt = m_SqliteHelper.compileStatement( "INSERT INTO MessageTbl " "( targetId, messageId, messageType, duration, " " errorHandler, preHandler, postHandler, userData, payload ) " "VALUES " "( ?, ?, ?, ?, " " ?, ?, ?, ?, ?);"); stmt.bind(i, szId); i++; stmt.bind(i, (const int)nMessageId); i++; stmt.bind(i, nMessageType); i++; stmt.bind(i, (const int)nDuration); i++; stmt.bind(i, (const int)nErrorHandler); i++; stmt.bind(i, (const int)nPreHandler); i++; stmt.bind(i, (const int)nPostHandler); i++; stmt.bind(i, (const int)nUserData); i++; stmt.bind(i, pszData, nDataLength); i++; stmt.execDML(); stmt.finalize(); Close(); return TRUE; } catch ( CppSQLite3Exception& e ) { Close(); XDEBUG(ANSI_COLOR_RED "DB ERROR: %d %s\r\n" ANSI_NORMAL, e.errorCode(), e.errorMessage()); } return FALSE; }
int GdbiCommands::sql( FdoStringP sql, int *qid ) { CheckDB(); int rc = RDBI_GENERIC_ERROR; rc = ::rdbi_est_cursor (m_pRdbiContext, qid); if( rc == RDBI_SUCCESS ) { if( SupportsUnicode() ) rc = ::rdbi_sqlW (m_pRdbiContext, *qid, sql ); else rc = ::rdbi_sql (m_pRdbiContext, *qid, sql ); } if( rc == RDBI_SUCCESS ) return rc; ThrowException(); return RDBI_GENERIC_ERROR; // to supress a compiler warning }
/** 해당 ID에 대한 전체 Message 삭제 */ BOOL CMessageHelper::Delete(const char *szId, BYTE nMessageType) { if(!CheckDB()) return FALSE; if(!Open()) return FALSE; try { CppSQLite3Statement stmt; if(nMessageType > 0) { stmt = m_SqliteHelper.compileStatement( "DELETE FROM MessageTbl " "WHERE targetId = ? AND messageType = ? ; "); stmt.bind(1, szId); stmt.bind(2, nMessageType); } else { stmt = m_SqliteHelper.compileStatement( "DELETE FROM MessageTbl " "WHERE targetId = ?; "); stmt.bind(1, szId); } stmt.execDML(); stmt.finalize(); Close(); } catch ( CppSQLite3Exception& e ) { Close(); XDEBUG(ANSI_COLOR_RED "DB ERROR DELETE: %d %s\r\n" ANSI_NORMAL, e.errorCode(), e.errorMessage()); return FALSE; } return TRUE; }
/** Message 조회 * * @param szId target device id * @param nMessageType 0 이라면 Message 전체 * @param pWrapper 응답을 전해 줄 IF4Wrapper */ BOOL CMessageHelper::Select(const char *szId, BYTE nMessageType, IF4Wrapper *pWrapper) { if(!CheckDB()) return FALSE; CppSQLite3Query result; char timeString[32]; TIMESTAMP issueTime; unsigned char * pPayload; int idx=0, nPayloadLen; int year, mon, day, hour, min, sec; if(pWrapper == NULL) return FALSE; if(!Open()) return FALSE; try { CppSQLite3Statement stmt; if (nMessageType > 0) { stmt = m_SqliteHelper.compileStatement( "SELECT " "messageId, issueTime, userData, payload, " "duration, errorHandler, preHandler, postHandler " "FROM MessageTbl " "WHERE targetId = ? and messageType = ? ; "); stmt.bind(1, szId); stmt.bind(2, nMessageType); } else { stmt = m_SqliteHelper.compileStatement( "SELECT " "messageId, issueTime, userData, payload, " "duration, errorHandler, preHandler, postHandler " "FROM MessageTbl " "WHERE targetId = ? ; "); stmt.bind(1, szId); } result = stmt.execQuery(); while(!result.eof()) { memset(timeString, 0, sizeof(timeString)); memset(&issueTime, 0, sizeof(TIMESTAMP)); pPayload = NULL; nPayloadLen = 0; idx = 0; IF4API_AddResultNumber(pWrapper, "1.6", VARSMI_UINT, result.getIntField(idx)); idx++; strcat(timeString, result.getStringField(idx)); idx++; sscanf(timeString,"%04d-%02d-%02d %02d:%02d:%02d", &year, &mon, &day, &hour, &min, &sec); issueTime.year = year; issueTime.mon = mon; issueTime.day = day; issueTime.hour = hour; issueTime.min = min; issueTime.sec = sec; /* XDEBUG(" %04d/%02d/%02d %02d:%02d:%02d\r\n", issueTime.year, issueTime.mon, issueTime.day, issueTime.hour, issueTime.min, issueTime.sec); */ IF4API_AddResultFormat(pWrapper, "1.16", VARSMI_TIMESTAMP, &issueTime, sizeof(TIMESTAMP)); IF4API_AddResultNumber(pWrapper, "1.6", VARSMI_UINT, result.getIntField(idx)); idx++; pPayload = const_cast<unsigned char *>(result.getBlobField(idx, nPayloadLen)); idx++; IF4API_AddResultFormat(pWrapper, "1.12", VARSMI_STREAM, pPayload, nPayloadLen); result.nextRow(); } stmt.finalize(); Close(); } catch ( CppSQLite3Exception& e ) { Close(); XDEBUG(ANSI_COLOR_RED "MessageTbl DB ERROR SELECT: %d %s\r\n" ANSI_NORMAL, e.errorCode(), e.errorMessage()); return FALSE; } return TRUE; }
FdoInt64 GdbiCommands::NextGDBISequenceNumber( FdoString* adbSequenceName ) { bool rc = false; FdoStringP strUse; int cursor; int select_begun = FALSE; FdoInt64 number = 0; int rows_proc; double doubleVal; gdbi_full_seq_def *gptr = &mFeatureSeq; CheckDB(); if (gptr->next < gptr->size) { number = gptr->sequence[gptr->next]; gptr->next++; rc = true; goto the_exit; } /* build SQL update command */ strUse = FdoStringP::Format( L"update %ls set startnum=startnum+%d where seqid='%ls';", ADB_SEQUENCE_TABLEW, ADB_SN_ALLOC_INCREMENT, adbSequenceName); if( sql( strUse, &cursor ) == RDBI_SUCCESS ) this->execute( cursor ); if( cursor != - 1 ) this->free_cursor( cursor ); /* build SQL update command */ strUse = FdoStringP::Format( L"select startnum from %ls where seqid='%ls';", ADB_SEQUENCE_TABLEW, adbSequenceName); if( ::rdbi_est_cursor(m_pRdbiContext, &cursor) != RDBI_SUCCESS ) goto the_exit; if (SupportsUnicode()) { if( ::rdbi_sql_vaW( m_pRdbiContext, RDBI_VA_EXEC, cursor, strUse, /* bind variables */ RDBI_VA_EOL, /* define variables */ RDBI_DOUBLE, 0, &doubleVal, RDBI_VA_EOL ) != RDBI_SUCCESS ) goto the_exit; } else { if( ::rdbi_sql_va( m_pRdbiContext, RDBI_VA_EXEC, cursor, strUse, /* bind variables */ RDBI_VA_EOL, /* define variables */ RDBI_DOUBLE, 0, &doubleVal, RDBI_VA_EOL ) != RDBI_SUCCESS ) goto the_exit; } if( ::rdbi_fetch (m_pRdbiContext, cursor, 1, &rows_proc) != RDBI_SUCCESS ) goto the_exit; if(rows_proc == 0) goto the_exit; number = (FdoInt64)doubleVal; gptr->size = ADB_SN_ALLOC_INCREMENT; for(int i=0; i<ADB_SN_ALLOC_INCREMENT;i++) gptr->sequence[i] = number--; gptr->next = 0; select_begun = TRUE; number = gptr->sequence[gptr->next]; gptr->next++; rc = true; the_exit: if (select_begun) rdbi_end_select(m_pRdbiContext, cursor); if( ! rc ) ThrowException(); return number; }
long GdbiCommands::NextRDBMSSequenceNumber( FdoString* adbSequenceName ) { bool rc = false; /* return code */ int switched_to_2 = FALSE; int tran_begun = FALSE; int select_begun = FALSE; int sqlid_coc = -1; FdoStringP sql_buf; /* place to format SQL command */ int rows_proc; gdbi_full_seq_def *gptr = &mFeatureSeq; long number = -1; int CURSOR = -1; FdoStringP sequenceName(adbSequenceName); CheckDB(); #ifndef USE_NONRDBMS_HEADER if (SupportsUnicode()) { if ( ::rdbi_get_next_seqW ( m_pRdbiContext, sequenceName, &number ) != RDBI_SUCCESS ) ThrowException(); } else { if ( ::rdbi_get_next_seq ( m_pRdbiContext, sequenceName, &number ) != RDBI_SUCCESS ) ThrowException(); } #else if ( (gptr->next < gptr->size) && (FdoCommonOSUtil::wcsicmp(adbSequenceName, gptr->seq_name) == 0) ) { number = gptr->sequence[gptr->next]; gptr->next++; rc = true; goto the_exit; } if (CURSOR == -1) { if( ::rdbi_est_cursor(m_pRdbiContext, &CURSOR) != RDBI_SUCCESS ) goto the_exit; select_begun = TRUE; /* build SQL select command */ sql_buf = FdoStringP::Format(L"select %ls.nextval from %ls", adbSequenceName, ADB_SEQUENCE_TABLEW); /* add the where clause for other than 'feature' numbers */ if (FdoCommonOSUtil::wcsicmp(adbSequenceName, ADB_FEATURESEQW) != 0) sql_buf += FdoStringP::Format(L" where %ls = '%ls'", ADB_SEQID_COLUMNW, adbSequenceName); if (SupportsUnicode()) { if( ::rdbi_sql_vaW( m_pRdbiContext, 0, CURSOR, sql_buf, /* bind variables */ RDBI_VA_EOL, /* define variables */ RDBI_LONG, 0, gptr->sequence, RDBI_VA_EOL ) != RDBI_SUCCESS ) goto the_exit; } else { if( ::rdbi_sql_va( m_pRdbiContext, 0, CURSOR, sql_buf, /* bind variables */ RDBI_VA_EOL, /* define variables */ RDBI_LONG, 0, gptr->sequence, RDBI_VA_EOL ) != RDBI_SUCCESS ) goto the_exit; } } if ( (0 == FdoCommonOSUtil::wcsicmp (adbSequenceName, ADB_FEATURESEQW)) || (0 == FdoCommonOSUtil::wcsicmp (adbSequenceName, ADB_USERSEQW))) { /* select next feature ids */ gptr->size = ADB_SN_ALLOC_INCREMENT; if( ::rdbi_exec_fetch(m_pRdbiContext, CURSOR, gptr->size, FALSE, &rows_proc) != RDBI_SUCCESS ) goto the_exit; if(rows_proc == 0) goto the_exit; gptr->next = 0; } else { if( ::rdbi_exec_fetch(m_pRdbiContext, CURSOR, 1, FALSE, &rows_proc) != RDBI_SUCCESS ) goto the_exit; if(rows_proc == 0) goto the_exit; gptr->size = 1; if(rows_proc == 0) goto the_exit; gptr->next = 0; } select_begun = TRUE; number = gptr->sequence[gptr->next]; gptr->next++; wcscpy( gptr->seq_name, adbSequenceName ); rc = true; the_exit: if (select_begun) { ::rdbi_end_select(m_pRdbiContext, CURSOR); ::rdbi_fre_cursor(m_pRdbiContext, CURSOR); } if( ! rc ) ThrowException(); #endif return number; }