Exemple #1
0
// 查询表数据
static int tbl_select(acl::db_handle& db)
{
	const char* sql = "select value, category, type from black_white_list";

	if (db.sql_select(sql) == false)
	{
		printf("select sql error\r\n");
		return (-1);
	}

	printf("\r\n---------------------------------------------------\r\n");

	const acl::db_rows* result = db.get_result();
	if (result)
	{
		const std::vector<acl::db_row*>& rows = result->get_rows();
		for (size_t i = 0; i < rows.size(); i++)
		{
			const acl::db_row* row = rows[i];
			for (size_t j = 0; j < row->length(); j++)
				printf("%s, ", (*row)[j]);
			printf("\r\n");
		}
	}

	int  ret = (int) db.length();

	// 释放查询结果
	db.free_result();
	return (ret);
}
Exemple #2
0
// 查询表数据
static int tbl_select(acl::db_handle& db, int n)
{
    const char* sql_fmt = "select * from group_tbl where"
                          " group_name='中国人-%d' and uvip_tbl='test'";

    acl::string sql;
    sql.format(sql_fmt, n);

    if (db.sql_select(sql.c_str()) == false)
    {
        printf("select sql error\r\n");
        return (-1);
    }

    // 列出查询结果方法一
    const acl::db_rows* result = db.get_result();
    if (result)
    {
        const std::vector<acl::db_row*>& rows = result->get_rows();
        for (size_t i = 0; i < rows.size(); i++)
        {
            if (n >= 5)
                continue;
            const acl::db_row* row = rows[i];
            for (size_t j = 0; j < row->length(); j++)
                printf("%s, ", (*row)[j]);
            printf("\r\n");
        }
    }

    // 列出查询结果方法二
    for (size_t i = 0; i < db.length(); i++)
    {
        if (n >= 5)
            continue;
        const acl::db_row* row = db[i];

        // 取出该行记录中某个字段的值
        const char* ptr = (*row)["group_name"];
        if (ptr == NULL)
        {
            printf(("error, no group name\r\n"));
            continue;
        }
        printf("group_name=%s: ", ptr);
        for (size_t j = 0; j < row->length(); j++)
            printf("%s, ", (*row)[j]);
        printf("\r\n");
    }

    int  ret = (int) db.length();

    // 释放查询结果
    db.free_result();
    return (ret);
}