//--------------------------------------------------------------------------- // Register this parition from the concept for test data. //--------------------------------------------------------------------------- bool CTDPartition::testRegisterPartition() { // Get the first record of the partition. CTDRecord* pFirstRec = getRecord(0); if (!pFirstRec) { ASSERT(false); return false; } int a = 0; CTDPartAttrib* pPartAttrib = NULL; CTDConcept* pCurrentConcept = NULL; for (POSITION pos = m_partAttribs.GetHeadPosition(); pos != NULL; ++a) { // Find the current concept of this attribute. pPartAttrib = m_partAttribs.GetNext(pos); pCurrentConcept = pFirstRec->getValue(a)->getCurrentConcept(); if (!pCurrentConcept) { ASSERT(false); return false; } pPartAttrib->m_relatedPos = pCurrentConcept->testRegisterPartition(this); } return true; }
char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable, LocaleConstant loc) { if (strlen(format) != fieldCount) return NULL; // each string field at load have array of string for each locale size_t stringHolderSize = sizeof(char*) * MAX_LOCALE; char* stringPool= new char[stringSize]; memcpy(stringPool,stringTable,stringSize); uint32 offset = 0; for (uint32 y = 0; y < recordCount; ++y) { for (uint32 x = 0; x < fieldCount; ++x) { switch (format[x]) { case FT_FLOAT: offset += sizeof(float); break; case FT_IND: case FT_INT: offset += sizeof(uint32); break; case FT_BYTE: offset += sizeof(uint8); break; case FT_STRING: { char** holder = *((char***)(&dataTable[offset])); char** slot = &holder[loc]; // fill only not filled entries if (*slot == nullStr) { const char* st = getRecord(y).getString(x); *slot = stringPool + (st - (const char*)stringTable); } offset+=sizeof(char*); break; } case FT_LOGIC: assert(false && "DBC files not have logic field type"); break; case FT_NA: case FT_NA_BYTE: case FT_SORT: break; default: assert(false && "unknown format character"); break; } } } return stringPool; }
QSqlRecord GenericDAO::getLocalRecord(const QString& where, const QVariantList& bindValues) const { DBPair* dbPair = DBPool::getInstance()->getInstanceDBPair(); Q_ASSERT(dbPair); return getRecord(dbPair->getDabaseLocal(), where, bindValues); }
/* * Used to get the Total Number of Tuples in the Table */ int getNumTuples (RM_TableData *rel) { int countOfTuples = 0; //to store the count of Total of number of Tuples RC getSuccess; //flag to mark the success of getting a record Record *record = (Record *)malloc(sizeof(Record)); RID rid; rid.page = 1; rid.slot = 0; //count until we reach the end of the table i.e. last page in the pageFile while(rid.page > 0 && rid.page < totalPages) { getSuccess = getRecord (rel, rid, record); /* * If fetching of record is Successfull, then increment the count */ if(getSuccess == RC_OK) { countOfTuples++; rid.page += 1; rid.slot = 0; } } record = NULL; free(record); // free record to avoid Memory leaks return countOfTuples;// returning the count }
// ************************************************************ void testCreateTableAndInsert (void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2} }; int numInserts = 9, i; Record *r; RID *rids; Schema *schema; testName = "test creating a new table and inserting tuples"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); //printf("\n Testing create table"); TEST_CHECK(createTable("test_table_r.txt",schema)); //printf("\n Testing open Table"); TEST_CHECK(openTable(table, "test_table_r.txt")); printf("\n Opened "); // insert rows into table for(i = 0; i < numInserts; i++) { printf("\n Inserting"); r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r.txt")); printf("\n Opened successsfully"); // randomly retrieve records from the table and compare to inserted ones for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid = rids[pos]; printf("\n getting records"); TEST_CHECK(getRecord(table, rid, r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[pos]), r, schema, "compare records"); } TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r.txt")); TEST_CHECK(shutdownRecordManager()); free(rids); free(table); TEST_DONE(); }
/** * Creates an index, and buckets and sorts the list of records into the index. */ void AlphabeticIndex::initBuckets(UErrorCode &errorCode) { if (U_FAILURE(errorCode) || buckets_ != NULL) { return; } buckets_ = createBucketList(errorCode); if (U_FAILURE(errorCode) || inputList_ == NULL || inputList_->isEmpty()) { return; } // Sort the records by name. // Stable sort preserves input order of collation duplicates. inputList_->sortWithUComparator(recordCompareFn, collator_, errorCode); // Now, we traverse all of the input, which is now sorted. // If the item doesn't go in the current bucket, we find the next bucket that contains it. // This makes the process order n*log(n), since we just sort the list and then do a linear process. // However, if the user adds an item at a time and then gets the buckets, this isn't efficient, so // we need to improve it for that case. Bucket *currentBucket = getBucket(*buckets_->bucketList_, 0); int32_t bucketIndex = 1; Bucket *nextBucket; const UnicodeString *upperBoundary; if (bucketIndex < buckets_->bucketList_->size()) { nextBucket = getBucket(*buckets_->bucketList_, bucketIndex++); upperBoundary = &nextBucket->lowerBoundary_; } else { nextBucket = NULL; upperBoundary = NULL; } for (int32_t i = 0; i < inputList_->size(); ++i) { Record *r = getRecord(*inputList_, i); // if the current bucket isn't the right one, find the one that is // We have a special flag for the last bucket so that we don't look any further while (upperBoundary != NULL && collatorPrimaryOnly_->compare(r->name_, *upperBoundary, errorCode) >= 0) { currentBucket = nextBucket; // now reset the boundary that we compare against if (bucketIndex < buckets_->bucketList_->size()) { nextBucket = getBucket(*buckets_->bucketList_, bucketIndex++); upperBoundary = &nextBucket->lowerBoundary_; } else { upperBoundary = NULL; } } // now put the record into the bucket. Bucket *bucket = currentBucket; if (bucket->displayBucket_ != NULL) { bucket = bucket->displayBucket_; } if (bucket->records_ == NULL) { bucket->records_ = new UVector(errorCode); if (bucket->records_ == NULL) { errorCode = U_MEMORY_ALLOCATION_ERROR; return; } } bucket->records_->addElement(r, errorCode); } }
qint64 HistoryManager::getLocation(const QUrl &url) { QVariantHash hostsRecord; hostsRecord[QLatin1String("host")] = url.host(); QUrl simplifiedUrl(url); simplifiedUrl.setScheme(QString()); simplifiedUrl.setHost(QString()); QVariantHash locationsRecord; locationsRecord[QLatin1String("host")] = getRecord(QLatin1String("hosts"), hostsRecord); locationsRecord[QLatin1String("scheme")] = url.scheme(); locationsRecord[QLatin1String("path")] = simplifiedUrl.toString(QUrl::RemovePassword | QUrl::NormalizePathSegments); return getRecord(QLatin1String("locations"), locationsRecord); }
char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable) { if (strlen(format) != fieldCount) return NULL; char* stringPool = new char[stringSize]; memcpy(stringPool, stringTable, stringSize); uint32 offset = 0; for (uint32 y = 0; y < recordCount; y++) { for (uint32 x = 0; x < fieldCount; x++) switch (format[x]) { case FT_FLOAT: case FT_IND: case FT_INT: offset += 4; break; case FT_BYTE: offset += 1; break; case FT_STRING: // fill only not filled entries char** slot = (char**) (&dataTable[offset]); if (!*slot || !**slot) { const char * st = getRecord(y).getString(x); *slot = stringPool + (st - (const char*) stringTable); } offset += sizeof(char*); break; } } return stringPool; }
std::string MWMechanics::Alchemy::getPotionName() const { if (const ESM::Potion *potion = getRecord()) return potion->mName; return ""; }
record_type annotate(Iterator begin, Iterator end, int gap, score_matrix const & matrix) { std::vector<alignment_result> vec(std::move(align(begin, end, gap, matrix, 1))); std::string & query = vec[0].first; std::string & target = vec[0].second; size_t target_id = vec[0].target_id; record_type result(std::distance(begin, end)); for (size_t i = 0; i < target.size(); ++i) { if (target[i] == '-' && i != 0) { data_type & data = result.push(std::numeric_limits<size_t>::max(), query[i]); data = result[result.size() - 2]; } else if (target[i] == '-' && i == 0) { result.push(std::numeric_limits<size_t>::max(), query[i]); } else if (query[i] == '-') { continue; } else { data_type & data = result.push(std::numeric_limits<size_t>::max(), query[i]); data = getRecord(target_id)[i]; } } return result; }
//--------------------------------------------------------------------------- // Deregister this parition from the concept. //--------------------------------------------------------------------------- bool CTDPartition::deregisterPartition() { CTDRecord* pFirstRec = NULL; if ( getNumRecords()== 0){ // Get the first record of the generalized records. pFirstRec = getGenRecords()->GetAt(0); } else { // Get the first record of the partition. pFirstRec = getRecord(0); if (!pFirstRec) { ASSERT(false); return false; } } int a = 0; CTDPartAttrib* pPartAttrib = NULL; CTDConcept* pCurrentConcept = NULL; for (POSITION pos = m_partAttribs.GetHeadPosition(); pos != NULL; ++a) { // Find the current concept of this attribute. pPartAttrib = m_partAttribs.GetNext(pos); pCurrentConcept = pFirstRec->getValue(a)->getCurrentConcept(); if (!pCurrentConcept) { ASSERT(false); return false; } pCurrentConcept->deregisterPartition(pPartAttrib->m_relatedPos); pPartAttrib->m_relatedPos = NULL; } return true; }
void MWMechanics::Alchemy::addPotion (const std::string& name) { ESM::Potion newRecord; newRecord.mData.mWeight = 0; for (TIngredientsIterator iter (beginIngredients()); iter!=endIngredients(); ++iter) if (!iter->isEmpty()) newRecord.mData.mWeight += iter->get<ESM::Ingredient>()->mBase->mData.mWeight; if (countIngredients() > 0) newRecord.mData.mWeight /= countIngredients(); newRecord.mData.mValue = mValue; newRecord.mData.mAutoCalc = 0; newRecord.mName = name; int index = OEngine::Misc::Rng::rollDice(6); assert (index>=0 && index<6); static const char *meshes[] = { "standard", "bargain", "cheap", "fresh", "exclusive", "quality" }; newRecord.mModel = "m\\misc_potion_" + std::string (meshes[index]) + "_01.nif"; newRecord.mIcon = "m\\tx_potion_" + std::string (meshes[index]) + "_01.dds"; newRecord.mEffects.mList = mEffects; const ESM::Potion* record = getRecord(newRecord); if (!record) record = MWBase::Environment::get().getWorld()->createRecord (newRecord); mAlchemist.getClass().getContainerStore (mAlchemist).add (record->mId, 1, mAlchemist); }
Record* RecordSet::getTopRecord() { if (isResult()) { return getRecord(0); } return NULL; }
// scan the next record and also return the actual record const Status HeapFileScan::scanNext(RID& outRid, Record& rec) { Status status; if ((status = scanNext(outRid)) != OK) return status; if ((status = getRecord(outRid, rec)) != OK) return status; return OK; }
void cAccounts::reload() { QMap< SERIAL, QString > characcnames; QStringList sockaccnames; cCharIterator iterChars; P_CHAR pc; for( pc = iterChars.first(); pc; pc = iterChars.next() ) { P_PLAYER pp = dynamic_cast<P_PLAYER>(pc); if( pp && pp->account() ) { characcnames.insert( pp->serial(), pp->account()->login() ); } } cUOSocket* mSock = NULL; for( mSock = cNetwork::instance()->first(); mSock; mSock = cNetwork::instance()->next() ) { if( mSock->account() ) sockaccnames.push_back( mSock->account()->login() ); else sockaccnames.push_back( QString() ); } clear(); load(); QMap< SERIAL, QString >::Iterator it = characcnames.begin(); while( it != characcnames.end() ) { P_PLAYER pp = dynamic_cast<P_PLAYER>(FindCharBySerial( it.key() )); if( pp ) pp->setAccount( getRecord( it.data() ), false ); ++it; } QStringList::iterator sit = sockaccnames.begin(); for( mSock = cNetwork::instance()->first(); mSock; mSock = cNetwork::instance()->next() ) { if( !(*sit).isNull() ) mSock->setAccount( getRecord( (*sit) ) ); ++sit; } }
/*============================================================================== Метод генерирует строку SQL-запроса на добавление записи в БД ==============================================================================*/ QString Model::generateInsert() { QString sql = "INSERT INTO " + schema.getTableName() + " ("; QStringList fieldList = schema.getFields(); QString fields, values; fields = fieldList.at(0); values = SQL::convertToSQLString(getRecord(fieldList.at(0))); for(int i = 1; i < fieldList.size(); ++i) { fields += ", " + fieldList.at(i); values += ", " + SQL::convertToSQLString(getRecord(fieldList.at(i))); } sql += fields + ") VALUES ("; sql += values + ")"; return sql; }
bool MUsers::get(QString userId, StrMap& user) { QSqlQuery qry; qry.exec("select users.*, permissions.label, permissions.account_id from users inner join permissions on users.id = permissions.user_id where users.id = "+ userId); if (! qry.next()) return false; user = getRecord(qry); return true; }
/** Devuelve todos los metros impresos*/ int In2Counters::getTotalMeters(){ QString req=QString("select Metros from Trabajos"); QStringList rslt=getRecord(req); int total=0; for (int x=0;x<rslt.count();x++){ total+=rslt.at(x).toInt(); } return total; }
bool ConfigManagerUnix::getConfigLong(const char* configItemName, long& outLongValue) { Record data; if(getRecord(configItemName,data)) { outLongValue = std::atol(data.mValue.c_str()); return true; } return false;}
void SearchIndex::run(string searchKey, string fileName, int records){ //-------------------------------------------------------------- //Preconditions: A key string values, a string containing a filename // of an index file, and the total number of records // //Postconditions: The integer value of the search key is returned // if found, else 0 is returned to the calling code // //Variables used: myFile: fstream object that accesses prog5.idx // infile: fstream object to the data file prog5.dat // sKey: integer value of the search key // offset: integer containing the RRN (offset) // keyArr[]: an integer array used to store keys // item: used to reference a Record object // bsearchResult: integer containing the result // of the binarySearchMethod // //-------------------------------------------------------------- fstream myFile(fileName.c_str(), ios::in); fstream infile("../instr/prog5.dat", ios::in); int sKey; sKey = convert(searchKey); int n=0; int key, offset; int keyArr[records]; int i = 0; Record item; while (myFile >> key >> offset) { while(i!=offset){ i++; } //Creates Item objects and writes the information contained within the object to the output file keyArr[i] = key; i=0; n++; } int bSearchResult = binarySearch(keyArr, records, sKey); if (bSearchResult > 0) { getRecord(bSearchResult); } else { cout << "Key not found, please try again." << endl; } }
bool recordDatabase::addToRecord(Field field, int valueToAdd){ if (isLoggedIn()){ DatabaseEntry *prevValue[MAX_FIELDS]; bool recordGotten = getRecord({ &field }, 1, prevValue); if (recordGotten){ return updateRecord(field, prevValue[0]->intValue + valueToAdd, false); } } return false; }
int MessageState::messageSize(int module, MessageTuple &t) { CursorStack stack; MessageRecord record; stack.init(module, t); if (getRecord(stack, true, record)) return strlen(record.string) + 1; else return 0; }
const std::string& Datastore::getValue(const std::string& key) { if (_good == false) { return gEmptyString; } auto r = getRecord(key); if (r && r->getType() == RecordType::kString) { return r->getVal(); } return gEmptyString; }
bool ConfigManagerUnix::getConfigFloat(const char* configItemName, float& outLongValue) { Record data; if(getRecord(configItemName,data)) { sscanf(data.mValue.c_str(),"%f",&outLongValue); return true; } return false; }
// getters // find a given item by case insensitive name in the config, return false if not found, true and value if found bool ConfigManagerUnix::getConfigString(const char* configItemName, std::string& outString) { Record data; if(getRecord(configItemName,data)) { outString = data.mValue; return true; } return false; }
void IDBServer::getRecord(const IDBRequestData& requestData, const IDBKeyRangeData& keyRangeData) { LOG(IndexedDB, "IDBServer::getRecord"); auto transaction = m_transactions.get(requestData.transactionIdentifier()); if (!transaction) return; transaction->getRecord(requestData, keyRangeData); }
bool rspfShapeDatabase::getNextRecord(rspfShapeDatabaseRecord& result) { if(isOpen() && ((theRecordNumber+1) < getNumberOfRecords())) { ++theRecordNumber; return getRecord(result); } return false; }
IOReturn WLCard::getIdentity(WLIdentity* wli) { size_t size = sizeof(WLIdentity); if (getRecord(0xFD20, (UInt16*)wli, &size) != kIOReturnSuccess) { WLLogErr("WLCard::getIdentity: getRecord failed\n"); return kIOReturnError; } return kIOReturnSuccess; }
char* DB2FileLoader::AutoProduceStrings(const char* format, char* dataTable, uint8 locale) { if (strlen(format) != fieldCount) return NULL; struct DB2StringHolder { char const* Strings[TOTAL_LOCALES]; }; // each string field at load have array of string for each locale size_t stringHolderSize = sizeof(char*) * TOTAL_LOCALES; char* stringPool= new char[stringSize]; memcpy(stringPool, stringTable, stringSize); uint32 offset = 0; for (uint32 y =0; y < recordCount; y++) { for (uint32 x = 0; x < fieldCount; x++) switch (format[x]) { case FT_FLOAT: case FT_IND: case FT_INT: offset += 4; break; case FT_BYTE: offset += 1; break; case FT_STRING: { DB2StringHolder** slot = (DB2StringHolder**)(&dataTable[offset]); if (*slot) // ensure the strings array holder is filled { const char * st = getRecord(y).getString(x); if (locale == 0) { // default locale, fill all unfilled locale entries for (uint8 loc = 0; loc < TOTAL_LOCALES; loc++) if (!(*slot)->Strings[loc] || (*slot)->Strings[loc] == nullStr) (*slot)->Strings[loc] = stringPool+(st-(const char*)stringTable); } else // specific locale, overwrite locale entry (*slot)->Strings[locale] = stringPool+(st-(const char*)stringTable); } offset+=sizeof(char*); break; } } } return stringPool; }
char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable) { if (strlen(format) != fieldCount) return nullptr; char* stringPool = new char[stringSize]; memcpy(stringPool, stringTable, stringSize); uint32 offset = 0; for (uint32 y = 0; y < recordCount; ++y) { for (uint32 x = 0; x < fieldCount; ++x) { switch (format[x]) { case FT_FLOAT: offset += sizeof(float); break; case FT_IND: case FT_INT: offset += sizeof(uint32); break; case FT_BYTE: offset += sizeof(uint8); break; case FT_STRING: { // fill only not filled entries char** slot = (char**)(&dataTable[offset]); if (!*slot || !** slot) { const char* st = getRecord(y).getString(x); *slot = stringPool + (st - (const char*)stringTable); } offset += sizeof(char*); break; } case FT_LOGIC: assert(false && "Attempted to load DBC files that does not have field types that match what is in the core. Check DBCfmt.h or your DBC files."); break; case FT_NA: case FT_NA_BYTE: case FT_SORT: break; default: assert(false && "Unknown field format character in DBCfmt.h"); break; } } } return stringPool; }