本文整理汇总了C++中ReadDB函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadDB函数的具体用法?C++ ReadDB怎么用?C++ ReadDB使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadDB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_migrate_unqualified_names
void test_migrate_unqualified_names(void)
{
DBHandle *db = setup(true);
assert_int_equal(WriteDB(db, "foo", &dummy_event, sizeof(dummy_event)), true);
assert_int_equal(WriteDB(db, "q.bar", &dummy_event, sizeof(dummy_event)), true);
CloseDB(db);
assert_int_equal(OpenDB(&db, dbid_bundles), true);
/* Old entry migrated */
assert_int_equal(HasKeyDB(db, "foo", strlen("foo") + 1), false);
assert_int_equal(HasKeyDB(db, "default.foo", strlen("default.foo") + 1), true);
Event read_value = { 0 };
ReadDB(db, "default.foo", &read_value, sizeof(read_value));
assert_memory_equal(&read_value, &dummy_event, sizeof(dummy_event));
/* New entry preserved */
assert_int_equal(HasKeyDB(db, "q.bar", strlen("q.bar") + 1), true);
memset(&read_value, 0, sizeof(read_value));
ReadDB(db, "q.bar", &read_value, sizeof(read_value));
assert_memory_equal(&read_value, &dummy_event, sizeof(dummy_event));
/* Version marker */
assert_int_equal(HasKeyDB(db, "version", strlen("version") + 1), true);
CloseDB(db);
}
示例2: test_migrate_single
void test_migrate_single(const char *expected_old_key,
const char *expected_quality_key)
{
/* Test migration of single entry */
DBHandle *db = setup(true);
KeyHostSeen0 khs0 = {
.q = 666777.0,
.expect = 12345.0,
.var = 6543210.0,
};
strcpy(khs0.address, "1.2.3.4");
assert_int_equal(WriteDB(db, expected_old_key, &khs0, sizeof(khs0)), true);
CloseDB(db);
assert_int_equal(OpenDB(&db, dbid_lastseen), true);
/* Old entry migrated */
assert_int_equal(HasKeyDB(db, expected_old_key,
strlen(expected_old_key) + 1), false);
/* Version marker */
assert_int_equal(HasKeyDB(db, "version", strlen("version") + 1), true);
/* Incoming connection quality */
KeyHostSeen khs;
assert_int_equal(ReadDB(db, expected_quality_key, &khs, sizeof(khs)), true);
assert_int_equal(khs.lastseen, 666777);
assert_double_close(khs.Q.q, 12345.0);
assert_double_close(khs.Q.expect, 12345.0);
assert_double_close(khs.Q.var, 6543210.0);
/* Address mapping */
char address[CF_BUFSIZE];
assert_int_equal(ReadDB(db, KEYHASH_KEY, address, sizeof(address)), true);
assert_string_equal(address, "1.2.3.4");
/* Reverse mapping */
char keyhash[CF_BUFSIZE];
assert_int_equal(ReadDB(db, "a1.2.3.4", keyhash, sizeof(keyhash)), true);
assert_string_equal(keyhash, KEYHASH);
CloseDB(db);
}
void test_migrate_incoming(void)
{
test_migrate_single(KEYHASH_IN, QUALITY_IN);
}
示例3: DelRec
/* Funkcija ierakstu dzesanai */
int DelRec(void) {
unsigned short int inputId; // Lietotāja inputs
if(ReadDB() == EXIT_SUCCESS) { // Izvadam visus ierakstus
printline("Enter ID of book you want to delete:");
scanf("%hu",&inputId);
__fpurge(stdin);
{
int my_rec, v_yes_no;;
while(
//Ejam cauri visiem atrastajiem ierakstiem (bet vajadzētu būt tikai vienam)
(my_rec =
searchElement( offsetof( struct book_rec_type, id)
//, member_size( struct book_rec_type, id)
, (int*)&inputId,
UNSIGNED_SHORT_INT )
) >= 0) {
// Prasam vai dzēst ierakstu
v_yes_no = askForConfirmation();
if(v_yes_no == 1)
//Dzēšam ierakstu
if(removeRecord(my_rec) == EXIT_SUCCESS)
printline("The record has been successfully removed");
}
}
}
示例4: memset
static Averages *GetCurrentAverages(char *timekey)
{
CF_DB *dbp;
static Averages entry;
if (!OpenDB(&dbp, dbid_observations))
{
return NULL;
}
memset(&entry, 0, sizeof(entry));
AGE++;
WAGE = AGE / SECONDS_PER_WEEK * CF_MEASURE_INTERVAL;
if (ReadDB(dbp, timekey, &entry, sizeof(Averages)))
{
int i;
for (i = 0; i < CF_OBSERVABLES; i++)
{
Log(LOG_LEVEL_DEBUG, "Previous values (%lf,..) for time index '%s'", entry.Q[i].expect, timekey);
}
}
else
{
Log(LOG_LEVEL_DEBUG, "No previous value for time index '%s'", timekey);
}
CloseDB(dbp);
return &entry;
}
示例5: AcquireLockByID
bool AcquireLockByID(const char *lock_id, int acquire_after_minutes)
{
CF_DB *dbp = OpenLock();
if(dbp == NULL)
{
return false;
}
bool result;
LockData lock_data;
if (ReadDB(dbp, lock_id, &lock_data, sizeof(lock_data)))
{
if(lock_data.time + (acquire_after_minutes * SECONDS_PER_MINUTE) < time(NULL))
{
result = WriteLockDataCurrent(dbp, lock_id);
}
else
{
result = false;
}
}
else
{
result = WriteLockDataCurrent(dbp, lock_id);
}
CloseLock(dbp);
return result;
}
示例6: InvalidateLockTime
bool InvalidateLockTime(const char *lock_id)
{
time_t epoch = 0;
CF_DB *dbp = OpenLock();
if (dbp == NULL)
{
return false;
}
LockData lock_data;
if(!ReadDB(dbp, lock_id, &lock_data, sizeof(lock_data)))
{
CloseLock(dbp);
return true; /* nothing to invalidate */
}
lock_data.time = epoch;
bool result = WriteLockData(dbp, lock_id, &lock_data);
CloseLock(dbp);
return result;
}
示例7: ReadDB
BOOL CEquipmentLocationDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// DWORD dwStyle =m_ctlCarsList.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
// dwStyle |= LVS_EX_GRIDLINES;
// dwStyle |= LVS_EX_FULLROWSELECT;
// m_ctlCarsList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
m_ctlCarsList.InsertColumn(0,"Car Number");
m_ctlCarsList.InsertColumn(1,"Reporting Marks");
m_ctlCarsList.InsertColumn(2,"Car Type");
m_ctlCarsList.InsertColumn(3,"E/L");
m_ctlCarsList.InsertColumn(4,"Last Movement");
m_ctlCarsList.InsertColumn(5,"Available on");
//
m_ctlCarsList.SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
m_ctlCarsList.SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
m_ctlCarsList.SetColumnWidth(2,85);
m_ctlCarsList.SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
m_ctlCarsList.SetColumnWidth(4,LVSCW_AUTOSIZE_USEHEADER);
m_ctlCarsList.SetColumnWidth(5,LVSCW_AUTOSIZE_USEHEADER);
//m_ctlCarsList.SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
//
ReadDB();
m_ctlCarsList.RestoreState("State","EquipmentLoocationDialog_m_ctlCarsList");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
示例8: DeleteIpFromLastSeen
/**
* @brief removes all traces of host 'ip' from lastseen DB
*
* @param[in] ip : either in (SHA/MD5 format)
* @param[in,out] digest: return corresponding digest of input host.
* If NULL, return nothing
* @retval true if entry was deleted, false otherwise
*/
bool DeleteIpFromLastSeen(const char *ip, char *digest)
{
DBHandle *db;
bool res = false;
if (!OpenDB(&db, dbid_lastseen))
{
Log(LOG_LEVEL_ERR, "Unable to open lastseen database");
return false;
}
char bufkey[CF_BUFSIZE + 1];
char bufhost[CF_BUFSIZE + 1];
strcpy(bufhost, "a");
strlcat(bufhost, ip, CF_BUFSIZE);
char key[CF_BUFSIZE];
if (ReadDB(db, bufhost, &key, sizeof(key)) == true)
{
strcpy(bufkey, "k");
strlcat(bufkey, key, CF_BUFSIZE);
if (HasKeyDB(db, bufkey, strlen(bufkey) + 1) == false)
{
res = false;
goto clean;
}
else
{
if (digest != NULL)
{
strcpy(digest, bufkey);
}
DeleteDB(db, bufkey);
DeleteDB(db, bufhost);
res = true;
}
}
else
{
res = false;
goto clean;
}
strcpy(bufkey, "qi");
strlcat(bufkey, key, CF_BUFSIZE);
DeleteDB(db, bufkey);
strcpy(bufkey, "qo");
strlcat(bufkey, key, CF_BUFSIZE);
DeleteDB(db, bufkey);
clean:
CloseDB(db);
return res;
}
示例9: LastseenMigration
bool LastseenMigration(DBHandle *db)
{
char version[64];
if (ReadDB(db, "version", version, sizeof(version)) == false)
{
return LastseenMigrationVersion0(db);
}
return true;
}
示例10: DBVersion
static size_t DBVersion(DBHandle *db)
{
char version[64];
if (ReadDB(db, "version", version, sizeof(version)) == false)
{
return 0;
}
else
{
return StringToLong(version);
}
}
示例11: ReadDB
void CLocationDialog::OnDelbutton()
{
if( MessageBox("Deleting a Location may have adverse effects on sidings, industries, trains, and. Are you sure you want to do this?","Delete Location?",MB_YESNO) == IDNO )
return;
int iSel = m_ctlLocationList.GetSelectionMark();
int iID = m_ctlLocationList.GetItemData(iSel);
CppSQLite3DB* pDB = &((CTrainOpsApp*)AfxGetApp())->m_pDB;
CString sSQL;
sSQL.Format("DELETE FROM Locations WHERE id=%d;",iID);
pDB->execDML(sSQL);
ReadDB();
}
示例12: NotePerformance
static void NotePerformance(char *eventname, time_t t, double value)
{
CF_DB *dbp;
Event e, newe;
double lastseen;
int lsea = SECONDS_PER_WEEK;
time_t now = time(NULL);
CfDebug("PerformanceEvent(%s,%.1f s)\n", eventname, value);
if (!OpenDB(&dbp, dbid_performance))
{
return;
}
if (ReadDB(dbp, eventname, &e, sizeof(e)))
{
lastseen = now - e.t;
newe.t = t;
newe.Q = QAverage(e.Q, value, 0.3);
/* Have to kickstart variance computation, assume 1% to start */
if (newe.Q.var <= 0.0009)
{
newe.Q.var = newe.Q.expect / 100.0;
}
}
else
{
lastseen = 0.0;
newe.t = t;
newe.Q.q = value;
newe.Q.dq = 0;
newe.Q.expect = value;
newe.Q.var = 0.001;
}
if (lastseen > (double) lsea)
{
CfDebug("Performance record %s expired\n", eventname);
DeleteDB(dbp, eventname);
}
else
{
CfOut(cf_verbose, "", "Performance(%s): time=%.4lf secs, av=%.4lf +/- %.4lf\n", eventname, value, newe.Q.expect,
sqrt(newe.Q.var));
WriteDB(dbp, eventname, &newe, sizeof(newe));
}
CloseDB(dbp);
}
示例13: Address2HostkeyInDB
static bool Address2HostkeyInDB(DBHandle *db, const char *address, char *result)
{
char address_key[CF_BUFSIZE];
char hostkey[CF_BUFSIZE];
/* Address key: "a" + address */
snprintf(address_key, CF_BUFSIZE, "a%s", address);
if (!ReadDB(db, address_key, &hostkey, sizeof(hostkey)))
{
return false;
}
char hostkey_key[CF_BUFSIZE];
char back_address[CF_BUFSIZE];
/* Hostkey key: "k" + hostkey */
snprintf(hostkey_key, CF_BUFSIZE, "k%s", hostkey);
if (!ReadDB(db, hostkey_key, &back_address, sizeof(back_address)))
{
/* There is no key -> address mapping. Remove reverse mapping and return failure. */
DeleteDB(db, address_key);
return false;
}
if (strcmp(address, back_address) != 0)
{
/* Forward and reverse mappings do not match. Remove reverse mapping and return failure. */
DeleteDB(db, address_key);
return false;
}
strlcpy(result, hostkey, CF_BUFSIZE);
return true;
}
示例14: Mon_RestoreFilePosition
static long Mon_RestoreFilePosition(char *name)
{
CF_DB *dbp;
long fileptr;
if (!OpenDB(&dbp, dbid_static))
{
return 0L;
}
ReadDB(dbp, name, &fileptr, sizeof(long));
Log(LOG_LEVEL_VERBOSE, "Resuming state for %s at %ld", name, fileptr);
CloseDB(dbp);
return fileptr;
}
示例15: Locations
void CLocationDialog::OnAddbutton()
{
CLocationDetailDialog pDlg;
if( pDlg.DoModal() != IDOK )
return;
CString sLocationName = pDlg.GetLocationName();
m_ctlLocationList.InsertItem(m_ctlLocationList.GetItemCount(),sLocationName);
//
// insert into database
//
CppSQLite3DB* pDB = &((CTrainOpsApp*)AfxGetApp())->m_pDB;
CString sSQL;
sSQL.Format("INSERT INTO Locations (name) VALUES (\"%s\")",sLocationName);
pDB->execQuery(sSQL);
//
ReadDB();
}