~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/pipe_query.c

  • Committer: Andrew Hutchings
  • Date: 2010-10-20 15:31:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1907.
  • Revision ID: andrew@linuxjedi.co.uk-20101020153127-w9djuz9omzezg2kz
Add error message for global sort buffer constraint

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