src/evsql/evsql.h
author Tero Marttila <terom@fixme.fi>
Fri, 28 Nov 2008 23:46:11 +0200
branchnew-evsql
changeset 45 424ce5ab82fd
parent 44 9e76ee9729b6
permissions -rw-r--r--
compiles + some basic evsql_test
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef EVSQL_INTERNAL_H
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define EVSQL_INTERNAL_H
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/*
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 * Internal interfaces
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 */
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include <sys/queue.h>
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include <event2/event.h>
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
#include "../evsql.h"
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
#include "../evpq.h"
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
/*
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
 * The engine type
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
 */
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
enum evsql_type {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    EVSQL_EVPQ,     // evpq
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
};
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
/*
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
 * Contains the type, engine configuration, list of connections and waiting query queue.
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
 */
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
struct evsql {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
    // what event_base to use
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
    struct event_base *ev_base;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
    // what engine we use
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
    enum evsql_type type;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
    // callbacks
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
    evsql_error_cb error_fn;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    void *cb_arg;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
    
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
    // engine-specific connection configuration
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
    union {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
        const char *evpq;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
    } engine_conf;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
    // list of connections that are open
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
    LIST_HEAD(evsql_conn_list, evsql_conn) conn_list;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
   
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
    // list of queries running or waiting to run
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
    TAILQ_HEAD(evsql_query_queue, evsql_query) query_queue;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
};
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
/*
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
 * A single connection to the server.
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
 *
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
 * Contains the engine connection, may have a transaction associated, and may have a query associated.
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
 */
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
struct evsql_conn {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
    // evsql we belong to
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
    struct evsql *evsql;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
    // engine-specific connection info
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
    union {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
        struct evpq_conn *evpq;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
    } engine;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
    // our position in the conn list
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
    LIST_ENTRY(evsql_conn) entry;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
    // are we running a transaction?
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
    struct evsql_trans *trans;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
    // are we running a transactionless query?
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
    struct evsql_query *query;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
};
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
/*
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
 * A single transaction.
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
 *
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
 * Has a connection associated and possibly a query (which will also be associated with the connection)
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
 */
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
struct evsql_trans {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
    // our evsql_conn/evsql
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
    struct evsql *evsql;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
    struct evsql_conn *conn;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    81
    
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
    // callbacks
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    83
    evsql_trans_error_cb error_fn;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    84
    evsql_trans_ready_cb ready_fn;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
    evsql_trans_done_cb done_fn;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
    void *cb_arg;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    88
    // the transaction type
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    89
    enum evsql_trans_type type;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    90
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
    // has evsql_trans_commit be called?
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
    int has_commit : 1;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
    // our current query
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
    struct evsql_query *query;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    97
};
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
/*
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   100
 * Backend result handle
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   101
 */
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   102
union evsql_result_handle {
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   103
    PGresult *pq;
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   104
};
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   105
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   106
/*
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
 * A single query.
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
 *
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   109
 * Has the info needed to exec the query (as these may be queued), and the callback/result info.
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
 */
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
struct evsql_query {
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    // the actual SQL query, this may or may not be ours, see _evsql_query_exec
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
    char *command;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
    
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
    // possible query params
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   116
    struct evsql_query_params_pq {
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
        int count;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   118
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   119
        Oid *types;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
        const char **values;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
        int *lengths;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
        int *formats;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   124
        // storage for numeric values
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   125
        union evsql_item_value *item_vals;
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   126
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
        int result_format;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
    } params;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
    // our callback
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   131
    evsql_query_cb cb_fn;
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
    void *cb_arg;
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   133
        
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   134
    // the result we get
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   135
    union evsql_result_handle result;
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
    // our position in the query list
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
    TAILQ_ENTRY(evsql_query) entry;
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   139
};
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   141
// the result
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   142
struct evsql_result {
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   143
    struct evsql *evsql;
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   144
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   145
    // possible error code
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   146
    int error;
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   147
    
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   148
    // the actual result
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   149
    union evsql_result_handle result;
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   150
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   151
    // result_* state
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   152
    struct evsql_result_info *info;
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   153
    size_t row_offset;
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   154
};
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   155
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   156
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
// maximum length for a 'BEGIN TRANSACTION ...' query
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   158
#define EVSQL_QUERY_BEGIN_BUF 512
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
40
03017f5f0087 add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   160
// the should the OID of some valid psql type... *ANY* valid psql type, doesn't matter, only used for NULLs
03017f5f0087 add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   161
// 16 = bool in 8.3
03017f5f0087 add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   162
#define EVSQL_PQ_ARBITRARY_TYPE_OID 16
03017f5f0087 add MODE param to makefile, fix INFO_DISABLED, add some constraints to the .sql, fix some -err's, EVSQL_PQ_ARBITRARY_TYPE_OID, and make read/write transactionless
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   163
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   164
/*
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   165
 * Core query-submission interface.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   166
 *
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   167
 * This performs some error-checking on the trans, allocates the evsql_query and does some basic initialization.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   168
 *
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   169
 * This does not actually enqueue the query anywhere, no reference is stored anywhere.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   170
 *
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   171
 * Returns the new evsql_query on success, NULL on failure.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   172
 */
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   173
struct evsql_query *_evsql_query_new (struct evsql *evsql, struct evsql_trans *trans, evsql_query_cb query_fn, void *cb_arg);
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   174
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   175
/*
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   176
 * Begin processing the given query, which should now be fully filled out.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   177
 *
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   178
 * If trans is given, it MUST be idle, and the query will be executed. Otherwise, it will either be executed directly
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   179
 * or enqueued for future execution.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   180
 *
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   181
 * Returns zero on success, nonzero on failure.
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   182
 */
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   183
int _evsql_query_enqueue (struct evsql *evsql, struct evsql_trans *trans, struct evsql_query *query, const char *command);
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   184
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   185
/*
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   186
 * Free the query and related resources, doesn't trigger any callbacks or remove from any queues.
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   187
 *
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   188
 * The command should already be taken care of (NULL).
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   189
 */
45
424ce5ab82fd compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   190
void _evsql_query_free (struct evsql_query *query);
44
9e76ee9729b6 more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   191
29
5de62ca9a5aa reorganize evsql into a separate dir, rename dbfs slightly, and split dbfs_op out from dirop (in prep for fileop)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   192
#endif /* EVSQL_INTERNAL_H */