-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I expression below sentens to transactd code? #29
Comments
Important points
Code samples (C++)(1) Did you mean that you want to check the existance of // To access to single record, using table class is faster.
table* tb = db->opneTable("test_info", TD_OPEN_READONL);
tb->setkeyNum(1);
tb->setFVN("UserSN", 100000000);
tb->seek();
if (tb->stat() == 0)
// record UserSN = 100000000 exists.
else if(tb->stat() == STATUS_NOT_FOUND_TI)
// Not found the record UserSN = 100000000.
else
// Other error. (2) Please calculate time stamp value ON THE CLIENT. // time stamp calculation function
double secondsFrom(const char* str)
{
tm t;
memset(&t, 0, sizeof(t));
strptime(str, "%Y-%m-%d %H:%M:%S", &t);
return difftime(mktime(&m), time(NULL));
}
// To access to single record, using table class is faster.
// Maybe, it is not necessary to select the fields.
table* tb = db->opneTable("test_info", TD_OPEN_READONL);
tb->setkeyNum(1);
tb->clearBuffer();
tb->setFVN("UserSN", 100000000);
tb->seek();
if (tb->stat() == 0)
{
const fields& fds = tb->fields();
printf("UserNick = %s", fds["UserNick"].c_str());
printf("Skin = %s", fds["Skin"].c_str());
printf("Level = %s", fds["Level"].c_str());
printf("LastUpdateFrom = %f second", secondsFrom(fds["LastUpdate"].c_str()));
} (3) In the same way, calculate CRC32 value ON THE CLIENT, before searching. unsigned int CRC32(const char*)
{
// ...snip...
}
unsigned int hashKey = CRC32("abcd");
// You can receive a result set with activaTable.
activeTable at(db, "reg_id_info", TD_OPEN_READONL);
recordset rs;
// Set query
query q;
q.select("UserSN", "MemberID").where("MemberIDHash", "=", hashKey).and_("MemberID" , "=", "abcd");
// Read records
at.index(1).keyValue(hashKey).read(rs, q);
row& r = rs.first();
printf("MemberID = %s", r["MemberID"].c_str()); |
Thank you for your answer. ^^ |
Related issue comment: #30 (comment) |
1 more please... ^^ SELECT COUNT(*) FROM result_stage WHERE UserSN = XXXXXXXX; How can I express this? |
There are some ways for counting records. |
The table schema is below CREATE TABLE
SELECT COUNT(1) FROM friend_request_info WHERE ReqSN = XXXXXXX AND RecvSN = XXXXXX; |
(1) You showed the following code on #29 (comment) :
It counts records on If you want to If you want to I will explain it with the answer of question (2). (2) It is important that "WHICH INDEX CAN YOU USE?". If you want to count record with a UNIQUE key (It means that return value is 0 or 1), tb->setKeyNum(0);
tb->setFV("InfoSN", "xxxx");
tb->seek(); // The only one access to the server. And read only one record.
count = tb->stat() == 0 ? 1 : 0; If you want to count records with duplicatable key, read all "ReqSN = xxxx" records on the server. With activeTable: recordset rs;
query q;
q.select("ReqSN").where("ReqSN" , "=", "xxxx").and_("RecvSN" , "=", "yyyy").reject(0xffff);
at.index(1).keyValue("xxxx").read(q, rs); // The only one access to the server. And read all "ReqSN = xxxx" record.
count = rs.size(); With table: query q;
q.select("ReqSN").where("ReqSN" , "=", "xxxx").and_("RecvSN" , "=", "yyyy").reject(0xffff);
tb->setQuery(q);
tb->setKeyNum(1);
tb->setFV("ReqSN", "xxxx");
tb->seekGreater(true); // The first access to the server.
if (tb->stat() == 0)
count = tb->recordCount(false, true); // The second access to the server. And read all "ReqSN = xxxx" record. If you can add the multiple-column-index With activeTable: query q;
recordset rs;
q.select("ReqSN").where("ReqSN" , "=", "xxxx").and_("RecvSN" , "=", "yyyy").reject(1);
at.index(3).keyValue("xxxx", "yyyy").read(q, rs); // The only one access to the server. And read fewest records.
count = rs.size(); With table: query q;
q.select("ReqSN").where("ReqSN" , "=", "xxxx").and_("RecvSN" , "=", "yyyy").reject(1);
tb->setQuery(q);
tb->setKeyNum(3);
tb->setFV("ReqSN", "xxxx");
tb->setFV("RecvSN", "yyyy");
tb->seekGreater(true); // The first access to the server.
if (tb->stat() == 0)
count = tb->recordCount(false, true); // The second access to the server. And read the fewest records. Above examples count the number of records. Modify q.select("ReqSN").where("ReqSN" , "=", "xxxx").and_("RecvSN" , "=", "yyyy").reject(0xffff).lmit(1).stopAtlimit(true); or q.select("ReqSN").where("ReqSN" , "=", "xxxx").and_("RecvSN" , "=", "yyyy").reject(1).lmit(1).stopAtlimit(true); |
Thank you so much. |
What different reject(0xffff) and reject(1) ? |
Please see #33 . |
The text was updated successfully, but these errors were encountered: