dict-sql.c revision 43d32cbe60fdaef2699d99f1ca259053e9350411
/* Copyright (C) 2005-2006 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "istream.h"
#include "str.h"
#include "sql-api-private.h"
#include "dict-private.h"
#include "dict-sql.h"
#include <unistd.h>
#include <fcntl.h>
struct sql_dict {
const char *connect_string, *username;
};
struct sql_dict_iterate_context {
struct dict_iterate_context ctx;
struct sql_result *result;
};
struct sql_dict_transaction_context {
struct dict_transaction_context ctx;
struct sql_transaction_context *sql_ctx;
unsigned int failed:1;
unsigned int changed:1;
};
{
int fd;
if (fd == -1) {
return -1;
}
continue;
t_push();
value++;
t_pop();
}
return -1;
}
return -1;
}
return -1;
}
return -1;
}
return -1;
}
return 0;
}
static struct dict *
const char *username)
{
return NULL;
}
t_push();
t_pop();
}
{
}
{
const char *p;
if (p == NULL)
return -1;
else
return -1;
return 0;
}
{
struct sql_result *result;
int ret;
bool priv;
return -1;
}
t_push();
if (priv) {
}
t_pop();
if (ret <= 0)
else {
*value_r =
}
return ret;
}
static struct dict_iterate_context *
enum dict_iterate_flags flags)
{
struct sql_dict_iterate_context *ctx;
bool priv;
else {
t_push();
"WHERE %s LIKE '%s/%%'",
if (priv) {
}
if ((flags & DICT_ITERATE_FLAG_RECURSE) == 0) {
}
if ((flags & DICT_ITERATE_FLAG_SORT_BY_KEY) != 0)
else if ((flags & DICT_ITERATE_FLAG_SORT_BY_VALUE) != 0)
t_pop();
}
}
{
struct sql_dict_iterate_context *ctx =
(struct sql_dict_iterate_context *)_ctx;
int ret;
return -1;
return ret;
return 1;
}
{
struct sql_dict_iterate_context *ctx =
(struct sql_dict_iterate_context *)_ctx;
}
static struct dict_transaction_context *
{
struct sql_dict_transaction_context *ctx;
}
{
struct sql_dict_transaction_context *ctx =
(struct sql_dict_transaction_context *)_ctx;
const char *error;
int ret;
ret = -1;
if (ret < 0)
} else {
/* nothing to be done */
ret = 0;
}
return ret;
}
{
struct sql_dict_transaction_context *ctx =
(struct sql_dict_transaction_context *)_ctx;
}
{
struct sql_dict_transaction_context *ctx =
(struct sql_dict_transaction_context *)_ctx;
const char *query;
bool priv;
return;
}
t_push();
if (priv) {
"INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s') "
"ON DUPLICATE KEY UPDATE %s = '%s'",
} else {
"INSERT INTO %s (%s, %s) VALUES ('%s', '%s') "
"ON DUPLICATE KEY UPDATE %s = '%s'",
}
t_pop();
}
const char *key)
{
struct sql_dict_transaction_context *ctx =
(struct sql_dict_transaction_context *)_ctx;
const char *query;
bool priv;
return;
}
t_push();
if (priv) {
"DELETE FROM %s WHERE %s = '%s' AND %s = '%s'",
} else {
"DELETE FROM %s WHERE %s = '%s'",
}
t_pop();
}
{
struct sql_dict_transaction_context *ctx =
(struct sql_dict_transaction_context *)_ctx;
const char *query;
bool priv;
return;
}
t_push();
if (priv) {
"INSERT INTO %s (%s, %s, %s) VALUES (%lld, '%s', '%s') "
"ON DUPLICATE KEY UPDATE %s = %s + %lld",
} else {
"INSERT INTO %s (%s, %s) VALUES (%lld, '%s') "
"ON DUPLICATE KEY UPDATE %s = %s + %lld",
}
t_pop();
}
{
}
};
static struct dict *dict_sql_drivers;
void dict_sql_register(void)
{
unsigned int i, count;
/* @UNSAFE */
for (i = 0; i < count; i++) {
dict_sql_drivers[i] = sql_dict;
}
}
void dict_sql_unregister(void)
{
int i;
}