~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/pipe_query.c

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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
 
 * Use and distribution licensed under the BSD license.  See
8
 
 * the COPYING.BSD file in the root source directory for full text.
 
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
 *
9
35
 */
10
36
 
11
 
#include "config.h"
 
37
 
 
38
#include <config.h>
12
39
 
13
40
#include <errno.h>
14
41
#include <stdio.h>
32
59
  size_t buffer_total= 0;
33
60
  ssize_t read_size= 0;
34
61
  drizzle_st drizzle;
35
 
  drizzle_con_st con;
 
62
  drizzle_con_st *con= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
36
63
  drizzle_result_st result;
37
64
  drizzle_return_t ret;
38
65
  drizzle_field_t field;
40
67
  size_t size;
41
68
  size_t total;
42
69
 
 
70
  if (con == NULL)
 
71
  {
 
72
    printf("Failed to allocate memory for drizzle connection");
 
73
    exit(1);
 
74
  }
 
75
 
43
76
  /* The docs say this might fail, so check for errors. */
44
77
  if (drizzle_create(&drizzle) == NULL)
45
78
  {
47
80
    exit(1);
48
81
  }
49
82
 
50
 
  if (drizzle_con_create(&drizzle, &con) == NULL)
 
83
  if (drizzle_con_create(&drizzle, con) == NULL)
51
84
  {
52
85
    printf("drizzle_con_create:%s\n", drizzle_error(&drizzle));
53
86
    exit(1);
58
91
    switch(c)
59
92
    {
60
93
    case 'd':
61
 
      drizzle_con_set_db(&con, optarg);
 
94
      drizzle_con_set_db(con, optarg);
62
95
      break;
63
96
 
64
97
    case 'h':
66
99
      break;
67
100
 
68
101
    case 'm':
69
 
      drizzle_con_add_options(&con, DRIZZLE_CON_MYSQL);
 
102
      drizzle_con_add_options(con, DRIZZLE_CON_MYSQL);
70
103
      break;
71
104
 
72
105
    case 'p':
95
128
    }
96
129
  }
97
130
 
98
 
  drizzle_con_set_tcp(&con, host, port);
99
 
  drizzle_con_set_auth(&con, user, password);
 
131
  drizzle_con_set_tcp(con, host, port);
 
132
  drizzle_con_set_auth(con, user, password);
100
133
 
101
134
  do
102
135
  {
108
141
 
109
142
    buffer_size+= (size_t)read_size;
110
143
 
111
 
    buffer= realloc(buffer, buffer_size + BUFFER_CHUNK);
 
144
    buffer= (char *)realloc(buffer, buffer_size + BUFFER_CHUNK);
112
145
    if (buffer == NULL)
113
146
    {
114
147
      printf("realloc:%d\n", errno);
118
151
    buffer_total= buffer_size + BUFFER_CHUNK;
119
152
  } while ((read_size= read(0, buffer + buffer_size, BUFFER_CHUNK)) != 0);
120
153
 
121
 
  (void)drizzle_query(&con, &result, buffer, buffer_size, &ret);
 
154
  (void)drizzle_query(con, &result, buffer, buffer_size, &ret);
122
155
  if (ret != DRIZZLE_RETURN_OK)
123
156
  {
124
157
    printf("drizzle_query:%s\n", drizzle_error(&drizzle));
166
199
  }
167
200
 
168
201
  drizzle_result_free(&result);
169
 
  drizzle_con_free(&con);
 
202
  drizzle_con_free(con);
170
203
  drizzle_free(&drizzle);
171
204
 
 
205
  free(con);
172
206
  return 0;
173
207
}