Пример #1
0
// 添加表数据
static bool tbl_insert(acl::db_handle& db, int n)
{
    const char* sql_fmt = "insert into group_tbl('group_name', 'uvip_tbl')"
                          " values('中国人-%d', 'test')";

    acl::string sql;
    sql.format(sql_fmt, n);
    if (db.sql_update(sql.c_str()) == false)
        return (false);

    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");
        }
    }

    db.free_result();
    return (true);
}
Пример #2
0
// 删除表数据
static bool tbl_delete(acl::db_handle& db, int n)
{
    const char* sql_fmt = "delete from group_tbl where group_name='中国人-%d'";

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

    if (db.sql_update(sql.c_str()) == false)
    {
        printf("delete sql error\r\n");
        return (false);
    }

    for (size_t i = 0; i < db.length(); i++)
    {
        const acl::db_row* row = db[i];
        for (size_t j = 0; j < row->length(); j++)
            printf("%s, ", (*row)[j]);
        printf("\r\n");
    }
    // 释放查询结果
    db.free_result();

    return (true);
}
Пример #3
0
// 添加表数据
static bool tbl_insert(acl::db_handle& db, int n)
{
	acl::query query;
	query.create_sql("insert into group_tbl(group_name, uvip_tbl,"
		" update_date) values(:group, :test, :date)")
		.set_format("group", "group:%d", n)
		.set_parameter("test", "test")
		.set_date("date", time(NULL), "%Y-%m-%d");

	if (db.exec_update(query) == false)
		return (false);

	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");
		}
	}

	db.free_result();
	return (true);
}
Пример #4
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);
}
Пример #5
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);
}
Пример #6
0
// 删除表数据
static bool tbl_delete(acl::db_handle& db, int n)
{
	acl::query query;
	query.create_sql("delete from group_tbl where group_name=:group")
		.set_format("group", "group-%d", n);

	if (db.exec_update(query) == false)
	{
		printf("delete sql error\r\n");
		return (false);
	}

	for (size_t i = 0; i < db.length(); i++)
	{
		const acl::db_row* row = db[i];
		for (size_t j = 0; j < row->length(); j++)
			printf("%s, ", (*row)[j]);
		printf("\r\n");
	}
	// 释放查询结果
	db.free_result();

	return (true);
}
Пример #7
0
// 查询表数据
static int tbl_select(acl::db_handle& db, int n)
{
	acl::query query;
	query.create_sql("select * from group_tbl where group_name=:group"
		" and uvip_tbl=:test")
		.set_format("group", "group:%d", n)
		.set_format("test", "test");

	if (db.exec_select(query) == 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++)
		{
			if (n > 100)
				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 > 100)
			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");
	}

	// 列出查询结果方法三
	const std::vector<acl::db_row*>* rows = db.get_rows();
	if (rows)
	{
		std::vector<acl::db_row*>::const_iterator cit = rows->begin();
		for (; cit != rows->end(); cit++)
		{
			if (n > 100)
				continue;
			const acl::db_row* row = *cit;
			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);
}