/*********************************************************************** ** GetExistingTableDesc() ** ** This function will attempt to get various pieces of information about ** a given table name. The table name needs to be fully qualified. ** A pointer to the table's description is returned. ************************************************************************/ TableDescription *GetExistingTableDesc(HDBC hdbc,char *table_name,ReturnStatus **RSPtr) { TableDescription *table_ptr; TableInfo *TPtr; // char FullTableName[SQL_MAX_TABLE_NAME_LEN+1]; *RSPtr=NULL; /* allocate space for the table description and initialize it */ table_ptr=(TableDescription *)malloc(sizeof(TableDescription)); memset(table_ptr,0,sizeof(TableDescription)); /* make name into fully-qualified name, if it already isn't */ /* error=FILENAME_RESOLVE_(table_name,(short)strlen(table_name), FullTableName,(short)sizeof(FullTableName), &fullname_length); FullTableName[fullname_length]=NULL; if(error){ printf("%s File System error %d returned from FILENAME_RESOLVE_\n", g_errstr,error); free(table_ptr); return(NULL); } */ /* allocate space for NOMAD specific information (used later) */ table_ptr->NomadInfoPtr=(NomadInfo *)malloc(sizeof(NomadInfo)); memset(table_ptr->NomadInfoPtr,0,sizeof(NomadInfo)); /* allocate space for table's info and fill it in with data */ table_ptr->TableInfoPtr=GetTableInfo(hdbc,table_name,FALSE,RSPtr); TPtr=table_ptr->TableInfoPtr; if(TPtr==NULL) { FreeTableDesc(table_ptr); return(NULL); } /* set other info values about the table */ /* switch(result.filetype){ case 1: TPtr->Organization=RELATIVE; break; case 2: TPtr->Organization=ENTRY_SEQ; break; case 0: // 0 mean unstructured file which we default to key-seq case 3: TPtr->Organization=KEY_SEQ; break; } */ /*>>>>might need to set additional NomadInfo values here */ /* find required columns to use for key, zerosum, abort and... */ /* ...last process id columns */ *RSPtr=FindRequiredColumns(table_ptr); if(*RSPtr!=NULL){ FreeTableDesc(table_ptr); return(NULL); } return(table_ptr); } /* end: GetExistingTableDesc() */
/********************************************************************** ** get_table_info ** ** This function fills in the needed information into the array of table ** descriptions. **********************************************************************/ short get_table_info(table_description *table_ptr[],short table_count) { short i; ReturnStatus *RSPtr; HENV henv; HDBC hdbc; HSTMT hstmt; Boolean connected; RETCODE rc; RSPtr=NULL; // start a connection so we can use it to get the table info connected=FullConnect(gDataSource,gUID,gPWD,&henv,&hdbc); if(!connected) return(FAILURE); rc=SQLAllocStmt(hdbc,&hstmt); //>>>> check return code ??? /* for each table, determine its format */ for(i=0;i<table_count;i++){ /* get format of table records, including column names */ if(table_ptr[i]->Organization==KEY_SEQ){ table_ptr[i]->pTable=GetTableInfo(hdbc,table_ptr[i]->TableName,FALSE,&RSPtr); } else{ table_ptr[i]->pTable=GetTableInfo(hdbc,table_ptr[i]->TableName,TRUE,&RSPtr); } if(table_ptr[i]->pTable==NULL) { LogReturnStatus(RSPtr); FreeReturnStatus(RSPtr); return(FAILURE); } else{ table_ptr[i]->henv=NULL; table_ptr[i]->hdbc=NULL; table_ptr[i]->hstmt=NULL; } } FullDisconnect(henv,hdbc); return(SUCCESS); } /* end of get_table_info() */
void DBMS::Describe(string tableName) { if (currentDb.length() == 0) { cout << "choose a database first!" << endl; return; } GetTableInfo(tableName, 0); char s[10]; string description = currentTable; description += "("; int i, j; for(i = 0; i < column.size(); i++) { description += column[i]; if(type[i] == 0) { description += " char("; sprintf(s, "%d", size[i]); description.append(s, size[i] / 10 + 1); description += ")"; } else if(type[i] == 1) { description += " int"; } for(j = 0; j < key.size(); j++) { if(key[j] == i) { description += " primary key"; break; } } if(column.size() - i == 1) { description += ")"; } else { description += ", "; } } cout << description << endl; }
/*********************************************************************** ** CreateSQLTable() ** ** This function creates the SQL tables (and some day indexes and views) ** which don't already exist and will be used by the processes. ************************************************************************/ short CreateSQLTable(TableDescription *table_ptr) { char command_line[SQL_MAX_COMMAND_LENGTH]; char *StringPtr; NomadInfo *NPtr; TableInfo *TPtr; TableInfo *TempTPtr; ReturnStatus *RSPtr; RETCODE rc; HENV henv; HDBC hdbc; HSTMT hstmt; short table_num; NPtr=table_ptr->NomadInfoPtr; TPtr=table_ptr->TableInfoPtr; RSPtr=NULL; henv=table_ptr->henv; hdbc=table_ptr->hdbc; hstmt=table_ptr->hstmt; printf("NOMAD: creating SQL table '%s'\n",TPtr->TableName); /* First, make sure any old SQL tables are deleted */ /* handle the case where NOPURGEUNTIL and SECURE */ /* are set so that we can't drop the tables */ /* sprintf(command_line,"ALTER TABLE %s SECURE 'OOOO' " "NOPURGEUNTIL 01 JAN 1980",TPtr->Tname); blank_pad(command_line,SQL_MAX_COMMAND_LENGTH); exec sql EXECUTE IMMEDIATE :command_line; if((sqlcode!=0)&&(sqlcode!=SQL_TABLE_NOT_FOUND)){ //>>> handle error somehow sql_error(); } */ // now drop the tables (ignore errors since we don't care if table are there or not) sprintf(command_line,"DROP TABLE %s",TPtr->TableName); rc=SQLExecDirect(hstmt,command_line,SQL_NTS); sprintf(command_line,"DROP TABLE %sV",TPtr->TableName); rc=SQLExecDirect(hstmt,command_line,SQL_NTS); /* handle creation like an existing table */ if(strlen(NPtr->like_name)!=0){ sprintf(command_line,"CREATE TABLE %s LIKE %s", TPtr->TableName,NPtr->like_name); rc=SQLExecDirect(hstmt,command_line,SQL_NTS); if(!CHECKRC(SQL_SUCCESS,rc,"SQLExecDirect")){ printf("%s return code=%d on %s\n",g_errstr,rc,command_line); LogAllErrors(henv,hdbc,hstmt); return(FAILURE); } } /* handle creation of a new table from scratch */ else { StringPtr=BuildCreateTableString(TPtr); if(strlen(StringPtr)==0) return(FAILURE); strncpy(g_CommandLine,StringPtr,sizeof(g_CommandLine)); rc=SQLExecDirect(hstmt,g_CommandLine,SQL_NTS); if(!CHECKRC(SQL_SUCCESS,rc,"SQLExecDirect")){ printf("%s return code=%d\n",g_errstr,rc); LogAllErrors(henv,hdbc,hstmt); if(gDebug) assert(FALSE); FormatForSQLCI(StringPtr); return(FAILURE); } free(StringPtr); } // get info about table we just created if(TPtr->Organization==KEY_SEQ){ TempTPtr=GetTableInfo(hdbc,TPtr->TableName,FALSE,&RSPtr); } else{ TempTPtr=GetTableInfo(hdbc,TPtr->TableName,TRUE,&RSPtr); } FreeTableInfo(TPtr); TPtr=TempTPtr; table_ptr->TableInfoPtr=TempTPtr; RSPtr=FindRequiredColumns(table_ptr); if(RSPtr!=NULL){ printf("ReturnType=%d ReturnCode=%d\n%s\n%s\n", RSPtr->ReturnType,RSPtr->ReturnCode, RSPtr->Message1,RSPtr->Message2); return(FAILURE); } /* add the table name to the list (if it's already in... */ /* ...the list then only its number is returned) */ table_num=add_table(TPtr->TableName); if(table_num<0) { printf("%s Problem with table '%s'\n",g_errstr,TPtr->TableName); return(FAILURE); } return(SUCCESS); } /* end: CreateSQLTable() */
void vSetDefaultForms( EXTDEVMODE *pEDM, HANDLE hPrinter, /* Access to the printer's data */ PRASDDUIINFO pRasdduiInfo /* Global Data Access */ ) { /* * The default form is the first in the array of PaperSizes. * Basically we need to set this into the first entry of the * aFMBin[] array, and also put the name into the DEVMODE. * This then defines at least a minimal configuration that * is valid for this printer. */ short sIndex; /* Mini driver index data */ PAPERSIZE *pPS; /* The paper size information */ WCHAR awchForm[ 64 ]; /* The name of the form */ short sDefaultPaperSrcIndex = -1 ; short sDefaultPaperSrc = 0; #if 0 sIndex = *((short *)((BYTE *)pdh + pdh->loHeap + pModel->rgoi[ MD_OI_PAPERSIZE ]) ); --sIndex; pPS = (PAPERSIZE *)GetTableInfoIndex( pdh, HE_PAPERSIZE, sIndex ); #endif pPS = (PAPERSIZE *)GetTableInfo( pdh, HE_PAPERSIZE, pEDM ); if( pPS ) sIndex = pPS->sPaperSizeID; /* The desired index */ else sIndex = 0; /* This should not happen ever */ if( sIndex >= pRasdduiInfo->cForms ) { if( sIndex > DMPAPER_USER ) { /* A minidriver specific size: use that string instead */ if( iLoadStringW( &WinResData, sIndex, awchForm, sizeof( awchForm ) ) ) { for( sIndex = 0; sIndex < pRasdduiInfo->cForms; ++sIndex ) { if( wcscmp( awchForm, (pFIBase + sIndex)->pName ) == 0 ) break; } if( sIndex >= pRasdduiInfo->cForms ) { /* Should not happen - we did not match the form */ sIndex = 0; /* It might work */ } } else { sIndex = 0; /* Should never happen! */ } } else { #if DBG DbgPrint( "rasdd!vSetDefaultForms: no match on default index %d\n", sIndex ); #endif sIndex = 0; } } else { /* * Reduce the value by 1: the resource IDs are one based, whereas * we are indexing an array, and so want a 0 based value. */ if( --sIndex < 0 ) sIndex = 0; } if( sIndex == (DMPAPER_LETTER - 1) && !bIsUSA( hPrinter ) ) { /* Letter size paper is default, and this is not USA, so use A4! */ sIndex = DMPAPER_A4 - 1; /* See above re - 1 */ } RASUIDBGP(DEBUG_TRACE,("Rasddui!vSetDefaultForms : Default PaperSize index is %d.\n",sIndex) ); /* Put the default form in default PaperSource */ /* Make the value 1 based */ sDefaultPaperSrcIndex = pEDM->dx.rgindex[ HE_PAPERSOURCE ] + 1; RASUIDBGP(DEBUG_TRACE,("Rasddui!vSetDefaultForms : Default PaperSrc Index is %d.\n",sDefaultPaperSrcIndex-1) ); /* Find the place of default Paper Source in FORM_MAP table. The value in rgindex[HE_PAPERSOURCE] * is papersource index value in the minidriver. We have to find out the place of this index * in the list. For example the list of papersource may be 1, 3, 5, 6 with 5 being the default. * In this case FORM_MAP table entry number 3 (aFMBin[ 3 ]) has to be selected as paper source * 5 is third in the order. */ if ( sDefaultPaperSrcIndex >= 1 ) { short *psrc; psrc = (short *)((BYTE *)pdh + pdh->loHeap + pModel->rgoi[ MD_OI_PAPERSOURCE ] ); for( sDefaultPaperSrc = 0 ; (*psrc && (*psrc != sDefaultPaperSrcIndex) ) ; ++sDefaultPaperSrc, ++psrc ) ; RASUIDBGP(DEBUG_TRACE,("Rasddui!vSetDefaultForms : Default PaperSource is %dth item in the list.\n",sDefaultPaperSrc) ); RASUIDBGP(DEBUG_TRACE,("Rasddui!vSetDefaultForms : Default PaperSrc Index in FORM_MAP table(aFMBin[%d]) is %d.\n",sDefaultPaperSrc, aFMBin[sDefaultPaperSrc].iPSIndex) ); RASUIDBGP(DEBUG_TRACE,("Rasddui!vSetDefaultForms : Total number of Paperbins is %d.\n",NumPaperBins) ); } if (sDefaultPaperSrc > NumPaperBins) sDefaultPaperSrc = 0; aFMBin[ sDefaultPaperSrc ].pfd = pFD + sIndex; if( pEDM ) { wcsncpy( pEDM->dm.dmFormName, aFMBin[ sDefaultPaperSrc ].pfd->pFI->pName, CCHFORMNAME ); pEDM->dm.dmFormName[ CCHFORMNAME - 1 ] = (WCHAR)0; pEDM->dm.dmPaperWidth = (short)aFMBin[ sDefaultPaperSrc ].pfd->pFI->Size.cx; pEDM->dm.dmPaperLength = (short)aFMBin[ sDefaultPaperSrc ].pfd->pFI->Size.cy; pEDM->dm.dmPaperSize = sIndex; pEDM->dm.dmFields |= DM_FORMNAME | DM_PAPERSIZE | DM_PAPERWIDTH | DM_PAPERLENGTH; } return; }
int wxLuaDebugData::GetTypeValue(lua_State *L, int stack_idx, int* wxl_type_, wxString& value) { wxCHECK_MSG(L, 0, wxT("Invalid lua_State")); int l_type = lua_type(L, stack_idx); int wxl_type = wxlua_luatowxluatype(l_type); switch (l_type) { case LUA_TNONE: { value = wxEmptyString; break; } case LUA_TNIL: { value = wxT("nil"); break; } case LUA_TBOOLEAN: { value = (lua_toboolean(L, stack_idx) != 0) ? wxT("true") : wxT("false"); break; } case LUA_TLIGHTUSERDATA: { value = GetUserDataInfo(L, stack_idx, false); break; } case LUA_TNUMBER: { double num = lua_tonumber(L, stack_idx); if ((long)num == num) value.Printf(wxT("%ld (0x%lx)"), (long)num, (unsigned long)num); else value.Printf(wxT("%g"), num); break; } case LUA_TSTRING: { value = lua2wx(lua_tostring(L, stack_idx)); break; } case LUA_TTABLE: { value = GetTableInfo(L, stack_idx); break; } case LUA_TFUNCTION: { value.Printf(wxT("%p"), lua_topointer(L, stack_idx)); if (lua_iscfunction(L, stack_idx)) wxl_type = WXLUA_TCFUNCTION; break; } case LUA_TUSERDATA: { value = GetUserDataInfo(L, stack_idx, true); break; } case LUA_TTHREAD: { value.Printf(wxT("%p"), lua_topointer(L, stack_idx)); break; } default : { value = wxEmptyString; break; } } if (wxl_type_) *wxl_type_ = wxl_type; return l_type; }
void DBMS::Insert(string words) { string tableName; string::size_type x, y; x = words.find("insert into", 0); if (x != string::npos) { x += 12; y = words.find(" ", x); if (y != string::npos) { tableName = words.substr(x, y - x); } } else return; GetTableInfo(tableName, 0); vector<string> value; int first = 0; int second = 0; for (int k = 0; k<this->column.size(); k++) { first = words.find("\"", first); second = words.find("\"", first + 1); value.push_back(words.substr(first + 1, second - first - 1)); first = second + 1; } string tabFile = ""; tabFile = GetWholeName(this->currentDb) + "\\" + this->currentTable + ".tab"; myfstream readfile; /*get file piece*/ readfile.open(tabFile); while (!readfile.end()) { char* piece = new char[piece_length]; readfile.read(piece); int max_tuple_num_in_piece = piece_length / this->tupleLength; for (int i = 0; i < max_tuple_num_in_piece; i++) { char* yuanzu = piece + i * (this->tupleLength + 1); if (yuanzu[0] == '\0') break; bool same = true; if (yuanzu[0] == 'y') { //yuanzu option for (int j = 0; j < this->key.size(); j++) { //check primaryKey int index = this->key[j]; int position = this->position[index]; string parameterValue = value[index]; string key = yuanzu + position + 1; if (key != parameterValue) { same = false; break; } } } if (same) {//if same ,quit delete[] piece; return; } } delete[] piece; } fstream writeTable; writeTable.open(tabFile.c_str(), ios::binary | ios::out | ios::in); writeTable.seekp(0, ios::end); int filelength = writeTable.tellp(); //补全piece不足一个元组的文件位置 int next_file_end = filelength + this->tupleLength + 1; int piece_eage = next_file_end / piece_length *piece_length; if ((piece_eage > filelength) && (piece_eage < next_file_end)) while (writeTable.tellp() < piece_eage) writeTable.put('\0'); writeTable.put('y'); for (int m = 0; m < this->column.size(); m++) { int contentSize = this->size[m]; string content = value[m]; int valueType = this->type[m]; if (valueType == 0) { content.append(contentSize, '\0'); writeTable.write(content.data(), contentSize); } else if (valueType == 1) { int number = atoi(content.data()); writeTable.write(reinterpret_cast<char*> (&number), contentSize); } } writeTable.close(); }