void CODBCRecordset::DoFieldExchange( CFieldExchange* pFX ) { pFX->SetFieldType( CFieldExchange::outputColumn ); CString cFieldName; for( UINT i = 0; i < m_nFields; i++ ) { cFieldName.Format( "[%s]", GetFieldName(i) ); switch( m_fields[i].m_dwType ) { case DBVT_NULL: break; case DBVT_BOOL: RFX_Bool( pFX, cFieldName, m_fields[i].m_boolVal ); break; case DBVT_UCHAR: RFX_Byte( pFX, cFieldName, m_fields[i].m_chVal ); break; case DBVT_SHORT: // CDBVariant::m_iVal is of type short // RFX_Int() requires parameter of type int. // Class wizard maps int variable in this case // but CDBVariand does not have int member. m_fields[i].m_dwType = DBVT_LONG; RFX_Long( pFX, cFieldName, m_fields[i].m_lVal ); break; case DBVT_LONG: RFX_Long( pFX, cFieldName, m_fields[i].m_lVal ); break; case DBVT_SINGLE: RFX_Single( pFX, cFieldName, m_fields[i].m_fltVal ); break; case DBVT_DOUBLE: RFX_Double( pFX, cFieldName, m_fields[i].m_dblVal ); break; case DBVT_DATE: RFX_Date( pFX, cFieldName, *m_fields[i].m_pdate ); break; case DBVT_STRING: { CODBCFieldInfo fi; GetODBCFieldInfo( i, fi ); RFX_Text( pFX, cFieldName, *m_fields[i].m_pstring, fi.m_nPrecision ); break; } case DBVT_BINARY: RFX_LongBinary( pFX, cFieldName, *(m_fields[i].m_pbinary) ); break; default: // Unknown datatype ASSERT( FALSE ); } m_fields[i].SetNull( FALSE != IsFieldStatusNull( i ) ); } }
void IBaseObj::_SerializeFieldStr(int i, rapidjson::Value& json, rapidjson::Document& root) { rapidjson::Value jsonName; rapidjson::Value jsonValue; jsonName.SetString(GetFieldName(i).c_str(), root.GetAllocator()); jsonValue.SetString(GetFieldStr(i).c_str()); json.AddMember(jsonName, jsonValue, root.GetAllocator()); }
unsigned int kGUIDBRecord::GetIndex(const char *fieldname) { unsigned int i; for(i=0; i<m_numfields; ++i) { if(!stricmp(GetFieldName(i),fieldname)) return(i); } assert(false,"Field not found error!"); return(0); }
const HashMap<String, String> *DatabaseQueryResult::FetchRow() { if (EndOfRow()) return nullptr; // Error! m_mapRow.Clear(); for (int i=0; i<m_nColumn; i++) m_mapRow.Add(GetFieldName(i), !GetCurrentValue(i) ? "" : GetCurrentValue(i)); IncRow(); // Return a pointer to the row map return &m_mapRow; }
kGUIDbQuery::kGUIDbQuery(kGUIDb *db,const char *query,...) { int i; int nf; kGUIString fquery; const char *errormsg; va_list args; /* for performance analysis */ db->IncNumQueries(); va_start(args, query); fquery.AVSprintf(query,args); va_end(args); if(db->GetTrace()) db->GetTrace()->ASprintf("->%s\n",fquery.GetString()); tryagain: ; mysql_query(db->GetConn(),fquery.GetString()); m_res_set = mysql_store_result(db->GetConn()); errormsg=mysql_error(db->GetConn()); if(errormsg[0]) { if(!strcmp(errormsg,"Lost connection to MySQL server during query")) { /* try to re-connect! */ db->ReConnect(); goto tryagain; } else if(!strcmp(errormsg,"Server shutdown in progress") || !strcmp(errormsg,"MySQL server has gone away")) { /* hmmm, not sure what to do here! */ return; } else assert(false,errormsg); } assert(m_res_set!=0,"Error, no result set!"); /* use a hash table for field->index conversion */ m_fi.Init(8,sizeof(int)); nf=GetNumFields(); for(i=0; i<nf; ++i) m_fi.Add(GetFieldName(i),&i); }
wxString iDBF::PrintDescription() { const int nf = GetNumOfField(); wxString xx=wxEmptyString, x; for (int i=0;i<nf;i++) { char *nm = GetFieldName(i); char ty = GetFieldType(i); int sz = GetFieldSize(i); int pr = GetFieldPrecision(i); x.Format("%12s %c %3d %2d\n",nm,ty,sz,pr); xx += x; } return wxString(xx); }
bool kGUIDBRecord::GetDiff(kGUIString *diff) { unsigned int i; bool changed; kGUIDBRecordEntry *re; diff->Clear(); changed=false; re=m_ce; for(i=0; i<m_numfields; ++i) { if(strcmp(re->m_newfieldvalues[i].GetString(),re->m_fieldvalues[i].GetString())) { if(changed==true) diff->Append(", "); diff->ASprintf("%s ('%s'<>'%s')",GetFieldName(i),re->m_newfieldvalues[i].GetString(),re->m_fieldvalues[i].GetString()); changed=true; } } return(changed); }
// ----------------------------------------------------------------------------- // CWPPushMessage::ParseContentType // ----------------------------------------------------------------------------- // void CWPPushMessage::ParseContentType( TLex8& aPointer ) { // Go through the whole content type header. while( !aPointer.Eos() ) { // Each parameter might be well-known (integer) or unknown (text) if( IsIntegerValue( aPointer ) ) { // For well-known parameters, the token is an integer value TUint paramToken( I64LOW( GetIntegerValue( aPointer ) ) ); // These are filled with results from parsing. TInt resultInteger( 0 ); TPtrC8 resultString; // Make sure paramToken fits into KParameterTypes table if( paramToken < sizeof(KParameterTypes)/sizeof(TParameterCodingType)) { // Get the coding and use it to determine how we should decode // the next parameter value. We actually ignore all results // except short integer (SEC) and text-value (MAC), but the // rest of the parameters have to be parsed anyway. TParameterCodingType coding( KParameterTypes[paramToken] ); switch( coding ) { case EQValue: GetQValue( aPointer ); break; case EWellKnownCharset: GetWellKnownCharset( aPointer ); break; case EVersionValue: GetVersionValue( aPointer ); break; case EIntegerValue: GetIntegerValue( aPointer ); break; case ETextString: GetTextString( aPointer ); break; case EFieldName: GetFieldName( aPointer ); break; case EShortInteger: resultInteger = GetShortInteger( aPointer ); break; case EConstrainedEncoding: GetConstrainedEncoding( aPointer ); break; case EDeltaSecondsValue: GetDeltaSecondsValue( aPointer ); break; case ENoValue: GetNoValue( aPointer ); break; case ETextValue: resultString.Set( GetTextValue( aPointer ) ); break; case EDateValue: GetDateValue( aPointer ); break; default: break; } // We have a result. We're actually only interested in // SEC and MAC parameters, so we save them here. switch( paramToken ) { case KWSPHeaderSEC: iSEC = resultInteger; break; case KWSPHeaderMAC: iMAC.Set( resultString ); break; default: break; } } } else { // Unknown parameter. Its name is in text, and the value // might be an integer or text. GetTokenText( aPointer ); if( IsIntegerValue( aPointer ) ) { GetIntegerValue( aPointer ); } else { GetTextValue( aPointer ); } } } }
bool kGUIDBRecord::Save(void) { unsigned int i; unsigned int e; int numchanged; bool changed; bool where; bool uselimit; kGUIString update; kGUIString field; kGUIDBRecordEntry *re; const char *errormsg; assert(m_tablename.GetLen()!=0,"Name not defined for table, call SetTableName(name)!"); /* locate using old key */ /* make sure all fields at the same as before changed */ /* if any are diffent, then return changed by other user error code, unlock table */ /* update fields that are different */ /* unlock table */ update.Alloc(8192); field.Alloc(1024); for(e=0; e<m_numentries; ++e) { re=m_entries.GetEntry(e); if(re->m_delete==true) { uselimit=true; where=true; changed=true; update.SetString("DELETE FROM "); update.Append(m_tablename.GetString()); } else if(re->m_new==true) { where=false; uselimit=false; update.SetString("INSERT "); update.Append(m_tablename.GetString()); update.Append(" SET "); changed=false; for(i=0; i<m_numfields; ++i) { if(changed==true) update.Append(", "); update.Append(GetFieldName(i)); update.Append("='"); m_db->EncodeField(&re->m_newfieldvalues[i],&field); update.Append(field.GetString()); update.Append("'"); changed=true; } } else /* update an existing record */ { update.SetString("UPDATE "); update.Append(m_tablename.GetString()); where=true; uselimit=true; update.Append(" SET "); changed=false; for(i=0; i<m_numfields; ++i) { if(strcmp(re->m_newfieldvalues[i].GetString(),re->m_fieldvalues[i].GetString())) { if(changed==true) update.Append(", "); update.Append(GetFieldName(i)); update.Append("='"); m_db->EncodeField(&re->m_newfieldvalues[i],&field); update.Append(field.GetString()); update.Append("'"); changed=true; } } } if(changed==true) { /* does this table have a unique primary key? */ if(where==true) { update.Append(" WHERE "); if(m_numprikeyfields) { unsigned int f; for(i=0; i<m_numprikeyfields; ++i) { f=m_prikey.GetEntry(i); if(i) update.Append("AND "); update.Append(GetFieldName(f)); update.Append("='"); m_db->EncodeField(&re->m_fieldvalues[f],&field); update.Append(field.GetString()); update.Append("' "); } } #if 0 if(m_unique==true) { update.Append(m_keyname.GetString()); update.Append("='"); update.Append(m_key.GetString()); update.Append("'"); } #endif else { for(i=0; i<m_numfields; ++i) { if(i) update.Append("AND "); update.Append(GetFieldName(i)); update.Append("='"); m_db->EncodeField(&re->m_fieldvalues[i],&field); update.Append(field.GetString()); update.Append("' "); } } } /* this is necessary as there could be multiple matches */ if(uselimit==true) update.Append(" LIMIT 1"); /* lock table */ LockTable(); m_db->UpdateLocks(); mysql_query(m_db->GetConn(),update.GetString()); if(m_db->GetTrace()) m_db->GetTrace()->ASprintf("->%s\n",update.GetString()); errormsg=mysql_error(m_db->GetConn()); if(errormsg[0]) assert(false,errormsg); numchanged=(int)mysql_affected_rows(m_db->GetConn()); assert(numchanged==1,"Error,number of records changed should have been one!"); /* fields were sucessfully written, copy new fields over previous ones */ /* hmmm, deleted entries? */ for(i=0; i<m_numfields; ++i) { re->m_new=false; if(strcmp(re->m_newfieldvalues[i].GetString(),re->m_fieldvalues[i].GetString())) re->m_fieldvalues[i].SetString(re->m_newfieldvalues[i].GetString()); } /* remove lock from this table */ UnLockTable(); m_db->UpdateLocks(); } } /* delete all entries that are flagged for deletion */ i=0; for(e=0; e<m_numentries; ++e) { re=m_entries.GetEntry(e-i); if(re->m_delete) { delete re; m_entries.DeleteEntry(e-i); ++i; /* ajust for scrolling entries */ } } m_numentries-=i; /* update number of entries */ return(true); /* ok! */ }