~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/simple_multi.cc

  • Committer: Mark Atwood
  • Date: 2011-11-22 17:04:41 UTC
  • mfrom: (2462.1.3 drizzle-include)
  • Revision ID: me@mark.atwood.name-20111122170441-5dehm0e0ax20z19b
mergeĀ lp:~brianaker/drizzle/fedora-16-fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 *
35
35
 */
36
36
 
37
 
#include <cstdio>
38
 
#include <cstring>
39
 
#include <cstdlib>
 
37
#include <stdio.h>
 
38
#include <string.h>
 
39
#include <stdlib.h>
40
40
 
41
41
#include <libdrizzle-2.0/drizzle_client.h>
42
42
 
45
45
int main(int argc, char *argv[])
46
46
{
47
47
  const char *query= "SELECT table_schema,table_name FROM tables";
48
 
  drizzle_st *drizzle;
49
 
 
50
 
  std::vector<drizzle_con_st *> cons;
51
 
  std::vector<drizzle_result_st *> result;
52
 
  std::vector<drizzle_query_st *> ql;
53
 
 
54
 
  if ((drizzle= drizzle_create()) == NULL)
 
48
  drizzle_st drizzle;
 
49
  drizzle_con_st *con;
 
50
  drizzle_result_st *result;
 
51
  drizzle_query_st *ql;
 
52
  drizzle_return_t ret;
 
53
  drizzle_row_t row;
 
54
  int x;
 
55
 
 
56
  con= (drizzle_con_st*)malloc(sizeof(drizzle_con_st) * SIMPLE_MULTI_COUNT);
 
57
  result= (drizzle_result_st*)malloc(sizeof(drizzle_result_st) * SIMPLE_MULTI_COUNT);
 
58
  ql= (drizzle_query_st*)malloc(sizeof(drizzle_query_st) * SIMPLE_MULTI_COUNT);
 
59
 
 
60
  if (drizzle_create(&drizzle) == NULL)
55
61
  {
56
 
    fprintf(stderr, "drizzle_create:NULL\n");
 
62
    printf("drizzle_create:NULL\n");
57
63
    return 1;
58
64
  }
59
65
 
60
66
  /* Create SIMPLE_MULTI_COUNT connections and initialize query list. */
61
 
  for (int x= 0; x < SIMPLE_MULTI_COUNT; x++)
 
67
  for (x= 0; x < SIMPLE_MULTI_COUNT; x++)
62
68
  {
63
 
    drizzle_con_st *con;
64
69
    if (x == 0)
65
70
    {
66
 
      if ((con= drizzle_con_create(drizzle)) == NULL)
 
71
      if (drizzle_con_create(&drizzle, &(con[0])) == NULL)
67
72
      {
68
 
        printf("drizzle_con_create:%s\n", drizzle_error(drizzle));
 
73
        printf("drizzle_con_create:%s\n", drizzle_error(&drizzle));
69
74
        return 1;
70
75
      }
71
76
 
72
77
      if (argc == 2 && !strcmp(argv[1], "-m"))
73
 
      {
74
 
        drizzle_con_add_options(con, DRIZZLE_CON_MYSQL);
75
 
      }
 
78
        drizzle_con_add_options(&(con[0]), DRIZZLE_CON_MYSQL);
76
79
      else if (argc != 1)
77
80
      {
78
81
        printf("usage: %s [-m]\n", argv[0]);
79
82
        return 1;
80
83
      }
81
84
 
82
 
      drizzle_con_set_db(con, "information_schema");
83
 
      cons.push_back(con);
 
85
      drizzle_con_set_db(&(con[0]), "information_schema");
84
86
    }
85
87
    else
86
88
    {
87
 
      if ((con= drizzle_con_clone(drizzle, cons[0])) == NULL)
 
89
      if (drizzle_con_clone(&drizzle, &(con[x]), &(con[0])) == NULL)
88
90
      {
89
 
        fprintf(stderr, "drizzle_con_clone:%s\n", drizzle_error(drizzle));
 
91
        printf("drizzle_con_clone:%s\n", drizzle_error(&drizzle));
90
92
        return 1;
91
93
      }
92
94
    }
93
95
 
94
 
    cons.push_back(con);
95
 
    drizzle_result_st *res= drizzle_result_create(con);
96
 
    result.push_back(res);
97
 
 
98
 
    drizzle_query_st *exec_query;
99
 
    if ((exec_query= drizzle_query_add(drizzle, NULL, con, res, query, strlen(query), DRIZZLE_QUERY_NONE, NULL)) == NULL)
 
96
    if (drizzle_query_add(&drizzle, &(ql[x]), &(con[x]), &(result[x]), query,
 
97
                          strlen(query), DRIZZLE_QUERY_NONE, NULL) == NULL)
100
98
    {
101
 
      fprintf(stderr, "drizzle_query_add:%s\n", drizzle_error(drizzle));
 
99
      printf("drizzle_query_add:%s\n", drizzle_error(&drizzle));
102
100
      return 1;
103
101
    }
104
 
    ql.push_back(exec_query);
105
102
  }
106
103
 
107
 
  drizzle_return_t ret= drizzle_query_run_all(drizzle);
 
104
  ret= drizzle_query_run_all(&drizzle);
108
105
  if (ret != DRIZZLE_RETURN_OK)
109
106
  {
110
 
    printf("drizzle_query_run_all:%s\n", drizzle_error(drizzle));
 
107
    printf("drizzle_query_run_all:%s\n", drizzle_error(&drizzle));
111
108
    return 1;
112
109
  }
113
110
 
114
 
  uint32_t x= 0;
115
 
  for (std::vector<drizzle_result_st *>::iterator iter= result.begin(); iter != result.end(); iter++)
 
111
  for (x= 0; x < SIMPLE_MULTI_COUNT; x++)
116
112
  {
117
 
    if (drizzle_result_error_code(*iter) != 0)
 
113
    if (drizzle_result_error_code(&(result[x])) != 0)
118
114
    {
119
 
      printf("%d:%s\n", drizzle_result_error_code(*iter),
120
 
             drizzle_result_error(*iter));
 
115
      printf("%d:%s\n", drizzle_result_error_code(&(result[x])),
 
116
             drizzle_result_error(&(result[x])));
121
117
      continue;
122
118
    }
123
119
 
124
 
    drizzle_row_t row;
125
 
    while ((row= drizzle_row_next(*iter)) != NULL)
126
 
    {
127
 
      printf("%x %s:%s\n", x, row[0], row[1]);
128
 
    }
129
 
    x++;
 
120
    while ((row= drizzle_row_next(&(result[x]))) != NULL)
 
121
      printf("%d %s:%s\n", x, row[0], row[1]);
130
122
  }
131
123
 
132
 
  drizzle_free(drizzle);
 
124
  drizzle_free(&drizzle);
133
125
 
 
126
  free(con);
 
127
  free(result);
 
128
  free(ql);
134
129
  return 0;
135
130
}