~ubuntu-branches/ubuntu/oneiric/pgpool2/oneiric

« back to all changes in this revision

Viewing changes to test/timestamp/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy
  • Date: 2010-02-17 13:58:08 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217135808-vqxtfe80r5z8toje
Tags: 2.3.2.1-0ubuntu1
* New upstream release (2.3.2.1)
 * Lots of bug fixes
 * Add SSL support
 * Add support for large object replication
 * Enhanced replication (TIMESTAMP, DATES)
 * Save node status on restart
 * Some other minor changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <string.h>
 
3
#include <stdio.h>
 
4
#include "pool.h"
 
5
#include "pool_proto_modules.h"
 
6
#include "pool_timestamp.h"
 
7
#include "parser/parser.h"
 
8
 
 
9
/* for get_current_timestamp() (MASTER() macro) */
 
10
POOL_REQUEST_INFO               _req_info;
 
11
POOL_REQUEST_INFO *Req_info = &_req_info;
 
12
int selected_slot = 0;          /* selected DB node */
 
13
int in_load_balance = 1;        /* non 0 if in load balance mode */
 
14
POOL_CONFIG _pool_config;
 
15
POOL_CONFIG *pool_config = &_pool_config;
 
16
 
 
17
typedef struct {
 
18
        char    *attrname;
 
19
        int              use_timestamp;
 
20
} TSAttr;
 
21
 
 
22
typedef struct {
 
23
        int             relnatts;
 
24
        TSAttr  attr[4];
 
25
} TSRel;
 
26
 
 
27
 
 
28
TSRel    rc[2] = {
 
29
        { 4, {
 
30
                { "c1", 0 },
 
31
                { "c2", 1 },
 
32
                { "c3", 0 },
 
33
                { "c4", 1 }
 
34
        } },
 
35
        { 4, {
 
36
                { "c1", 0 },
 
37
                { "c2", 0 },
 
38
                { "c3", 0 },
 
39
                { "c4", 0 }
 
40
        } }
 
41
};
 
42
 
 
43
POOL_RELCACHE *
 
44
pool_create_relcache(int cachesize, char *sql, func_ptr register_func, func_ptr unregister_func, bool issessionlocal)
 
45
{
 
46
        return (POOL_RELCACHE *) 1;
 
47
}
 
48
 
 
49
void *
 
50
pool_search_relcache(POOL_RELCACHE *relcache, POOL_CONNECTION_POOL *backend, char *table)
 
51
{
 
52
        if (strcmp(table, "\"rel1\"") == 0)
 
53
                return (void *) &(rc[0]);
 
54
        else
 
55
                return (void *) &(rc[1]);
 
56
}
 
57
 
 
58
POOL_STATUS
 
59
do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result, int major) {
 
60
        static POOL_SELECT_RESULT res;
 
61
        static char *data[1] = {
 
62
                "2009-01-01 23:59:59.123456+09"
 
63
        };
 
64
 
 
65
        res.numrows = 1;
 
66
        res.data = data;
 
67
 
 
68
        *result = &res;
 
69
        return POOL_CONTINUE; 
 
70
}
 
71
 
 
72
int
 
73
main(int argc, char **argv)
 
74
{
 
75
        char            *query;
 
76
        List            *tree;
 
77
        ListCell        *l;
 
78
        Portal           portal;
 
79
        POOL_CONNECTION_POOL    backend;
 
80
        POOL_CONNECTION_POOL_SLOT slot;
 
81
        backend.slots[0] = &slot;
 
82
 
 
83
        pool_config->replication_enabled = 1;
 
84
 
 
85
        if (argc != 2)
 
86
        {
 
87
                fprintf(stderr, "./timestmp-test query\n");
 
88
                exit(1);
 
89
        }
 
90
 
 
91
        tree = raw_parser(argv[1]);
 
92
        if (tree == NULL)
 
93
        {
 
94
                printf("syntax error: %s\n", argv[1]);
 
95
        }
 
96
        else
 
97
        {
 
98
                foreach(l, tree)
 
99
                {
 
100
                        portal.num_tsparams = 0;
 
101
                        Node *node = (Node *) lfirst(l);
 
102
                        query = rewrite_timestamp(&backend, node, false, &portal);
 
103
                        if (query)
 
104
                                printf("%s\n", query);
 
105
                        else
 
106
                                printf("%s\n", argv[1]);
 
107
 
 
108
                }
 
109
        }
 
110
        return 0;
 
111
}
 
112
 
 
113
void child_exit(int code) { exit (code); }
 
114
void pool_error(const char *fmt,...) {}
 
115
void pool_debug(const char *fmt,...) {}
 
116
void pool_log(const char *fmt,...) {}
 
117
void free_select_result(POOL_SELECT_RESULT *result) {}