~drizzle-trunk/drizzle/development

1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
1
/*
2
 * Drizzle Client & Protocol Library
3
 *
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
 * All rights reserved.
6
 *
7
 * Use and distribution licensed under the BSD license.  See
1799.2.4 by Monty Taylor
Made BSD files reference root BSD file.
8
 * the COPYING.BSD file in the root source directory for full text.
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
9
 */
10
11
#include <stdio.h>
12
#include <string.h>
1929.1.30 by Stewart Smith
fix missing include in simple_multi.c
13
#include <stdlib.h>
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
14
15
#include <libdrizzle/drizzle_client.h>
16
17
#define SIMPLE_MULTI_COUNT 10
18
19
int main(int argc, char *argv[])
20
{
21
  const char *query= "SELECT table_schema,table_name FROM tables";
22
  drizzle_st drizzle;
1929.1.28 by Stewart Smith
fix simple_multi stack size fix
23
  drizzle_con_st *con;
24
  drizzle_result_st *result;
25
  drizzle_query_st *ql;
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
26
  drizzle_return_t ret;
27
  drizzle_row_t row;
28
  int x;
29
1929.1.31 by Stewart Smith
fix alloc in simple_multi.c from stack usage fix
30
  con= (drizzle_con_st*)malloc(sizeof(drizzle_con_st) * SIMPLE_MULTI_COUNT);
31
  result= (drizzle_result_st*)malloc(sizeof(drizzle_result_st) * SIMPLE_MULTI_COUNT);
32
  ql= (drizzle_query_st*)malloc(sizeof(drizzle_query_st) * SIMPLE_MULTI_COUNT);
1929.1.26 by Stewart Smith
fix large stack ussage of examples/simple_multi.c:
33
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
34
  if (drizzle_create(&drizzle) == NULL)
35
  {
36
    printf("drizzle_create:NULL\n");
37
    return 1;
38
  }
39
40
  /* Create SIMPLE_MULTI_COUNT connections and initialize query list. */
41
  for (x= 0; x < SIMPLE_MULTI_COUNT; x++)
42
  {
43
    if (x == 0)
44
    {
45
      if (drizzle_con_create(&drizzle, &(con[0])) == NULL)
46
      {
47
        printf("drizzle_con_create:%s\n", drizzle_error(&drizzle));
48
        return 1;
49
      }
50
51
      if (argc == 2 && !strcmp(argv[1], "-m"))
52
        drizzle_con_add_options(&(con[0]), DRIZZLE_CON_MYSQL);
53
      else if (argc != 1)
54
      {
55
        printf("usage: %s [-m]\n", argv[0]);
56
        return 1;
57
      }
58
59
      drizzle_con_set_db(&(con[0]), "information_schema");
60
    }
61
    else
62
    {
63
      if (drizzle_con_clone(&drizzle, &(con[x]), &(con[0])) == NULL)
64
      {
65
        printf("drizzle_con_clone:%s\n", drizzle_error(&drizzle));
66
        return 1;
67
      }
68
    }
69
70
    if (drizzle_query_add(&drizzle, &(ql[x]), &(con[x]), &(result[x]), query,
71
                          strlen(query), 0, NULL) == NULL)
72
    {
73
      printf("drizzle_query_add:%s\n", drizzle_error(&drizzle));
74
      return 1;
75
    }
76
  }
77
78
  ret= drizzle_query_run_all(&drizzle);
79
  if (ret != DRIZZLE_RETURN_OK)
80
  {
81
    printf("drizzle_query_run_all:%s\n", drizzle_error(&drizzle));
82
    return 1;
83
  }
84
85
  for (x= 0; x < SIMPLE_MULTI_COUNT; x++)
86
  {
87
    if (drizzle_result_error_code(&(result[x])) != 0)
88
    {
89
      printf("%d:%s\n", drizzle_result_error_code(&(result[x])),
90
             drizzle_result_error(&(result[x])));
91
      continue;
92
    }
93
94
    while ((row= drizzle_row_next(&(result[x]))) != NULL)
95
      printf("%d %s:%s\n", x, row[0], row[1]);
96
  }
97
98
  drizzle_free(&drizzle);
99
1929.1.26 by Stewart Smith
fix large stack ussage of examples/simple_multi.c:
100
  free(con);
101
  free(result);
102
  free(ql);
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
103
  return 0;
104
}