~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/sqlite_server.c

  • Committer: Monty Taylor
  • Date: 2010-09-28 07:45:44 UTC
  • mto: (1799.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1800.
  • Revision ID: mordred@inaugust.com-20100928074544-s3ujnv6s8wro74l2
Added BSD copying file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
5
 * All rights reserved.
6
6
 *
7
 
 * Redistribution and use in source and binary forms, with or without
8
 
 * modification, are permitted provided that the following conditions are
9
 
 * met:
10
 
 *
11
 
 *     * Redistributions of source code must retain the above copyright
12
 
 * notice, this list of conditions and the following disclaimer.
13
 
 *
14
 
 *     * Redistributions in binary form must reproduce the above
15
 
 * copyright notice, this list of conditions and the following disclaimer
16
 
 * in the documentation and/or other materials provided with the
17
 
 * distribution.
18
 
 *
19
 
 *     * The names of its contributors may not be used to endorse or
20
 
 * promote products derived from this software without specific prior
21
 
 * written permission.
22
 
 *
23
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 
 *
 
7
 * Use and distribution licensed under the BSD license.  See
 
8
 * the COPYING file in this directory for full text.
35
9
 */
36
10
 
37
 
 
38
11
#include <errno.h>
39
12
#include <stdio.h>
40
13
#include <stdlib.h>
93
66
  bool mysql= false;
94
67
  in_port_t port= 0;
95
68
  drizzle_return_t ret;
96
 
  sqlite_server *server= (sqlite_server*)malloc(sizeof(sqlite_server));
97
 
  drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
 
69
  sqlite_server server;
 
70
  drizzle_con_st con_listen;
98
71
 
99
 
  server->db= NULL;
100
 
  server->verbose= DRIZZLE_VERBOSE_NEVER;
 
72
  server.db= NULL;
 
73
  server.verbose= DRIZZLE_VERBOSE_NEVER;
101
74
 
102
75
  while((c = getopt(argc, argv, "c:h:mp:v")) != -1)
103
76
  {
120
93
      break;
121
94
 
122
95
    case 'v':
123
 
      server->verbose++;
 
96
      server.verbose++;
124
97
      break;
125
98
 
126
99
    default:
135
108
    return 1;
136
109
  }
137
110
 
138
 
  sqlite3_open(argv[optind], &(server->db));
139
 
  if (server->db == NULL)
 
111
  sqlite3_open(argv[optind], &(server.db));
 
112
  if (server.db == NULL)
140
113
  {
141
114
    printf("sqlite3_open: could not open sqlite3 db\n");
142
115
    return 1;
143
116
  }
144
117
 
145
 
  if (drizzle_create(&(server->drizzle)) == NULL)
 
118
  if (drizzle_create(&server.drizzle) == NULL)
146
119
  {
147
120
    printf("drizzle_create:NULL\n");
148
121
    return 1;
149
122
  }
150
123
 
151
 
  drizzle_add_options(&(server->drizzle), DRIZZLE_FREE_OBJECTS);
152
 
  drizzle_set_verbose(&(server->drizzle), server->verbose);
 
124
  drizzle_add_options(&server.drizzle, DRIZZLE_FREE_OBJECTS);
 
125
  drizzle_set_verbose(&server.drizzle, server.verbose);
153
126
 
154
 
  if (drizzle_con_create(&(server->drizzle), con_listen) == NULL)
 
127
  if (drizzle_con_create(&server.drizzle, &con_listen) == NULL)
155
128
  {
156
129
    printf("drizzle_con_create:NULL\n");
157
130
    return 1;
158
131
  }
159
132
 
160
 
  drizzle_con_add_options(con_listen, DRIZZLE_CON_LISTEN);
161
 
  drizzle_con_set_tcp(con_listen, host, port);
 
133
  drizzle_con_add_options(&con_listen, DRIZZLE_CON_LISTEN);
 
134
  drizzle_con_set_tcp(&con_listen, host, port);
162
135
 
163
136
  if (mysql)
164
 
    drizzle_con_add_options(con_listen, DRIZZLE_CON_MYSQL);
 
137
    drizzle_con_add_options(&con_listen, DRIZZLE_CON_MYSQL);
165
138
 
166
 
  if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
 
139
  if (drizzle_con_listen(&con_listen) != DRIZZLE_RETURN_OK)
167
140
  {
168
 
    printf("drizzle_con_listen:%s\n", drizzle_error(&(server->drizzle)));
 
141
    printf("drizzle_con_listen:%s\n", drizzle_error(&server.drizzle));
169
142
    return 1;
170
143
  }
171
144
 
172
145
  while (1)
173
146
  {
174
 
    (void)drizzle_con_accept(&(server->drizzle), &(server->con), &ret);
 
147
    (void)drizzle_con_accept(&server.drizzle, &server.con, &ret);
175
148
    if (ret != DRIZZLE_RETURN_OK)
176
149
    {
177
 
      printf("drizzle_con_accept:%s\n", drizzle_error(&(server->drizzle)));
 
150
      printf("drizzle_con_accept:%s\n", drizzle_error(&server.drizzle));
178
151
      return 1;
179
152
    }
180
153
 
181
 
    server_run(server);
 
154
    server_run(&server);
182
155
 
183
 
    drizzle_con_free(&(server->con));
 
156
    drizzle_con_free(&server.con);
184
157
 
185
158
    if (count > 0)
186
159
    {
191
164
    }
192
165
  }
193
166
 
194
 
  drizzle_con_free(con_listen);
195
 
  drizzle_free(&(server->drizzle));
196
 
  sqlite3_close(server->db);
197
 
  free(con_listen);
198
 
  free(server);
 
167
  drizzle_con_free(&con_listen);
 
168
  drizzle_free(&server.drizzle);
 
169
  sqlite3_close(server.db);
199
170
 
200
171
  return 0;
201
172
}
337
308
  sqlite_server *server= (sqlite_server *)data;
338
309
  drizzle_return_t ret;
339
310
  int x;
340
 
  size_t *sizes= (size_t*)malloc(sizeof(size_t)*8192);
 
311
  size_t sizes[8192];
341
312
 
342
313
  if (server->send_columns == true)
343
314
  {
404
375
 
405
376
  server->rows++;
406
377
 
407
 
  free(sizes);
408
 
 
409
378
  return 0;
410
379
}
411
380