本文整理汇总了C++中MySQLResult::fetchRow方法的典型用法代码示例。如果您正苦于以下问题:C++ MySQLResult::fetchRow方法的具体用法?C++ MySQLResult::fetchRow怎么用?C++ MySQLResult::fetchRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQLResult
的用法示例。
在下文中一共展示了MySQLResult::fetchRow方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: daemon_getemail
static void daemon_getemail()
{
if (userID.empty()) {
daemon_printf( "%d unknow user id\n", CODE_DENIED );
return;
}
if (init_database()) {
daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED );
return;
}
std::string sql;
sql = "SELECT email FROM user_basic WHERE id=";
sql += userID;
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d query failed\n", CODE_DENIED );
return;
}
MySQLResult *res = stardictdMain.conn.getResult();
if (!res) {
daemon_printf( "%d get result failed\n", CODE_DENIED );
return;
}
DB_ROW row = res->fetchRow();
if (!row) {
res->destroy();
daemon_printf( "%d fetch row failed\n", CODE_DENIED );
return;
}
daemon_printf( "%d\n", CODE_OK );
net_write_str(row[0]);
res->destroy();
}
示例2: daemon_change_password
static void daemon_change_password(std::string &user, std::string &base64_rsa_md5saltsum_old_password, std::string &base64_rsa_md5saltsum_new_password)
{
std::vector<unsigned char> v;
base64_decode(base64_rsa_md5saltsum_old_password, v);
std::vector<unsigned char> v2;
rsa_decrypt(v, v2, RSA_Public_Key_d, RSA_Public_Key_n);
std::string old_passwd;
vector_to_string(v2, old_passwd);
base64_decode(base64_rsa_md5saltsum_new_password, v);
rsa_decrypt(v, v2, RSA_Public_Key_d, RSA_Public_Key_n);
std::string new_passwd;
vector_to_string(v2, new_passwd);
if (new_passwd.length()!=32) {
daemon_printf( "%d wrong new password\n", CODE_DENIED );
return;
}
if (init_database()) {
daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED );
return;
}
std::string sql;
if (auth_user != "root") {
sql = "SELECT user_md5saltpassword FROM stardict_users WHERE username=";
AppendMysql(sql, user.c_str());
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d Query failed!\n", CODE_DENIED );
return;
}
MySQLResult *res = stardictdMain.conn.getResult();
if (!res) {
daemon_printf( "%d Get result failed!\n", CODE_DENIED );
return;
}
DB_ROW row = res->fetchRow();
if (!row) {
res->destroy();
daemon_printf( "%d user doesn't exist\n", CODE_DENIED );
return;
}
if (old_passwd != row[0]) {
res->destroy();
daemon_printf( "%d old password is wrong\n", CODE_DENIED );
return;
}
res->destroy();
}
sql = "UPDATE stardict_users SET user_md5saltpassword=";
AppendMysql(sql, new_passwd.c_str());
sql += " WHERE username=";
AppendMysql(sql, user.c_str());
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d Query failed!\n", CODE_DENIED );
return;
}
daemon_printf( "%d\n", CODE_OK );
}
示例3: daemon_getdictmask
static void daemon_getdictmask()
{
if (userID.empty()) {
daemon_printf( "%d unknow user id\n", CODE_USER_NOT_REGISTER );
return;
}
if (init_database()) {
daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED );
return;
}
std::string sql;
sql = "SELECT dictmask FROM user_basic WHERE id=";
sql += userID;
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d query failed\n", CODE_DENIED );
return;
}
MySQLResult *res = stardictdMain.conn.getResult();
if (!res) {
daemon_printf( "%d get result failed\n", CODE_DENIED );
return;
}
DB_ROW row = res->fetchRow();
if (!row) {
res->destroy();
daemon_printf( "%d fetch row failed\n", CODE_DENIED );
return;
}
daemon_printf( "%d\n", CODE_OK );
const char *dictmask = row[0];
char *str = g_strdup_printf("level-%d-user/max_dict_count", userLevel);
const int max_dict_count = stardictdMain.conf->get_int(str);
g_free(str);
std::string dictmask_str = stardictdMain.oLibs.get_dicts_list(dictmask, max_dict_count, userLevel);
net_write_str(dictmask_str.c_str());
res->destroy();
}
示例4: f_mysql_result
Variant f_mysql_result(CVarRef result, int row,
CVarRef field /* = null_variant */) {
MySQLResult *res = php_mysql_extract_result(result);
if (res == NULL) return false;
MYSQL_RES *mysql_result = NULL;
MYSQL_ROW sql_row = NULL;
unsigned long *sql_row_lengths = NULL;
if (res->isLocalized()) {
if (!res->seekRow(row)) return false;
if (!res->fetchRow()) return false;
} else {
mysql_result = res->get();
if (row < 0 || row >= (int)mysql_num_rows(mysql_result)) {
raise_warning("Unable to jump to row %d on MySQL result index %d",
row, result.toResource()->o_getId());
return false;
}
mysql_data_seek(mysql_result, row);
sql_row = mysql_fetch_row(mysql_result);
if (!sql_row) {
return false;
}
sql_row_lengths = mysql_fetch_lengths(mysql_result);
if (!sql_row_lengths) {
return false;
}
}
int field_offset = 0;
if (!field.isNull()) {
if (field.isString()) {
String sfield = field.toString();
const char *tmp = strchr(sfield.data(), '.');
String table_name, field_name;
if (tmp) {
int pos = tmp - sfield.data();
table_name = sfield.substr(0, pos);
field_name = sfield.substr(pos + 1);
} else {
field_name = sfield;
}
int i = 0;
bool found = false;
res->seekField(0);
while (i < res->getFieldCount()) {
MySQLFieldInfo *info = res->getFieldInfo(i);
if ((table_name.empty() || table_name.same(info->table)) &&
field_name.same(info->name)) {
field_offset = i;
found = true;
break;
}
i++;
}
if (!found) { /* no match found */
raise_warning("%s%s%s not found in MySQL result index %d",
table_name.data(), (table_name.empty() ? "" : "."),
field_name.data(), result.toResource()->o_getId());
return false;
}
} else {
field_offset = field.toInt32();
if (field_offset < 0 ||
field_offset >= (int)res->getFieldCount()) {
raise_warning("Bad column offset specified");
return false;
}
}
}
if (res->isLocalized()) {
Variant f = res->getField(field_offset);
if (!f.isNull()) {
return f.toString();
}
} else {
if (sql_row[field_offset]) {
return String(sql_row[field_offset], sql_row_lengths[field_offset],
CopyString);
}
}
return uninit_null();
}
示例5: daemon_auth
static void daemon_auth(std::string &user, std::string &key)
{
if (user == "guest") {
daemon_printf( "%d\n", CODE_OK );
return;
}
char *buf;
struct MD5Context ctx;
unsigned char digest[16];
char hex[33];
if (user == "root") {
std::string &root_password = stardictdMain.conf->get_str("root-user/password");
if (root_password.empty()) {
daemon_printf( "%d auth denied\n", CODE_DENIED );
return;
}
MD5Init(&ctx);
MD5Update(&ctx, (const unsigned char*)"StarDict", 8); //StarDict-Protocol 0.4, add md5 salt.
MD5Update(&ctx, (const unsigned char*)root_password.c_str(), root_password.length());
MD5Final(digest, &ctx);
for (int i = 0; i < 16; i++)
snprintf( hex+2*i, 3, "%02x", digest[i] );
hex[32] = '\0';
buf = g_strdup_printf("%s%s", daemonStamp, hex);
} else {
if (init_database()) {
daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED );
return;
}
std::string sql;
sql = "SELECT user_id, user_md5saltpassword, level FROM stardict_users WHERE username=";
AppendMysql(sql, user.c_str());
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d Query failed!\n", CODE_DENIED );
return;
}
MySQLResult *res = stardictdMain.conn.getResult();
if (!res) {
daemon_printf( "%d Get result failed!\n", CODE_DENIED );
return;
}
DB_ROW row = res->fetchRow();
if (!row) {
res->destroy();
daemon_printf( "%d User doesn't exist!\n", CODE_DENIED );
return;
}
userID = row[0];
userLevel = atoi(row[2]);
stardictdMain.SetUserLevel(userLevel);
buf = g_strdup_printf("%s%s", daemonStamp, row[1]);
res->destroy();
}
MD5Init(&ctx);
MD5Update(&ctx, (const unsigned char*)buf, strlen(buf));
MD5Final(digest, &ctx);
for (int i = 0; i < 16; i++)
snprintf( hex+2*i, 3, "%02x", digest[i] );
hex[32] = '\0';
g_free(buf);
if (key != hex) {
daemon_printf( "%d auth denied\n", CODE_DENIED );
return;
} else {
daemon_printf( "%d authenticated\n", CODE_OK );
auth_user=user;
if (auth_user == "root") {
stardictdMain.SetDictMask("", 0, 0);
} else {
std::string sql;
sql = "SELECT dictmask, collatefunc, language FROM user_basic WHERE id=";
sql+= userID;
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d Query failed!\n", CODE_DENIED );
return;
}
MySQLResult *res = stardictdMain.conn.getResult();
if (!res) {
daemon_printf( "%d Get result failed!\n", CODE_DENIED );
return;
}
DB_ROW row = res->fetchRow();
if (row) {
char *str = g_strdup_printf("level-%d-user/max_dict_count", userLevel);
const int max_dict_count = stardictdMain.conf->get_int(str);
g_free(str);
stardictdMain.SetDictMask(row[0], max_dict_count, userLevel);
bool enable_collate;
if (userLevel == 0) {
enable_collate = stardictdMain.conf->get_bool("level-0-user/enable_collate");
} else {
enable_collate = true;
}
if (enable_collate) {
stardictdMain.SetServerCollateFunc(atoi(row[1]));
} else {
stardictdMain.SetServerCollateFunc(0);
}
stardictdMain.SetUserLang(row[2]);
} else {
//.........这里部分代码省略.........
示例6: daemon_userlevel
static void daemon_userlevel(std::string &user, std::string &fromlevel, std::string &tolevel)
{
if (auth_user != "root") {
daemon_printf( "%d no permission\n", CODE_DENIED );
return;
}
int from = atoi(fromlevel.c_str());
if (fromlevel.empty() || from<0 || from>5) {
daemon_printf( "%d wrong from-level\n", CODE_DENIED );
return;
}
int to = atoi(tolevel.c_str());
if (tolevel.empty() || to<0 || to>5 || to==from) {
daemon_printf( "%d wrong to-level\n", CODE_DENIED );
return;
}
if (init_database()) {
daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED );
return;
}
std::string sql;
sql = "SELECT level FROM stardict_users WHERE username=";
AppendMysql(sql, user.c_str());
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d query user level failed\n", CODE_DENIED );
return;
}
MySQLResult *res = stardictdMain.conn.getResult();
if (!res) {
daemon_printf( "%d Get result failed!\n", CODE_DENIED );
return;
}
DB_ROW row = res->fetchRow();
if (!row) {
res->destroy();
daemon_printf( "%d user doesn't exist.\n", CODE_DENIED );
return;
}
int clevel = atoi(row[0]);
res->destroy();
if (clevel != from) {
daemon_printf( "%d current level is %d.\n", CODE_DENIED, clevel );
return;
}
sql = "UPDATE stardict_users SET level=";
gchar *str = g_strdup_printf("%d", to);
sql += str;
g_free(str);
sql += " WHERE username=";
AppendMysql(sql, user.c_str());
if (stardictdMain.conn.query(sql.c_str(), sql.length())) {
daemon_printf( "%d query failed\n", CODE_DENIED );
return;
}
std::string text;
text = "Set user level: ";
text += user;
text += ' ';
text += fromlevel;
text += ' ';
text += tolevel;
stardictdMain.logger->log(LOG_ACCOUNT, text.c_str());
daemon_printf( "%d\n", CODE_OK );
}