~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/simple.cc

  • Committer: Mark Atwood
  • Date: 2011-08-12 20:36:52 UTC
  • mfrom: (2385.3.5 rf)
  • Revision ID: me@mark.atwood.name-20110812203652-ljc8c0q8s8pzuxei
mergeĀ lp:~olafvdspek/drizzle/client

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
int main(int argc, char *argv[])
48
48
{
49
 
  const char* db= "information_schema";
50
49
  const char* host= NULL;
51
50
  const char* user= NULL;
52
51
  const char* password= NULL;
53
 
  bool mysql= false;
54
52
  in_port_t port= 0;
55
 
  const char* query= "select table_schema, table_name from tables";
56
 
  drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
57
53
 
58
54
  for (int c; (c = getopt(argc, argv, "d:h:mp:u:P:q:v")) != -1; )
59
55
  {
60
56
    switch (c)
61
57
    {
62
 
    case 'd':
63
 
      db= optarg;
64
 
      break;
65
 
 
66
58
    case 'h':
67
59
      host= optarg;
68
60
      break;
69
61
 
70
 
    case 'm':
71
 
      mysql= true;
72
 
      break;
73
 
 
74
62
    case 'p':
75
63
      port= static_cast<in_port_t>(atoi(optarg));
76
64
      break;
83
71
      password = optarg;
84
72
      break;
85
73
 
86
 
    case 'q':
87
 
      query= optarg;
88
 
      break;
89
 
 
90
 
    case 'v':
91
 
      if (verbose < DRIZZLE_VERBOSE_MAX)
92
 
        verbose= static_cast<drizzle_verbose_t>(verbose + 1);
93
 
      break;
94
 
 
95
74
    default:
96
75
      cout << 
97
 
        "usage: " << argv[0] << " [-d <db>] [-h <host>] [-m] [-p <port>] [-q <query>] [-v]\n"
98
 
        "\t-d <db>    - Database to use for query\n"
 
76
        "usage:\n"
99
77
        "\t-h <host>  - Host to connect to\n"
100
 
        "\t-m         - Use the MySQL protocol\n"
101
78
        "\t-p <port>  - Port to connect to\n"
102
79
        "\t-u <user>  - User\n"
103
 
        "\t-P <pass>  - Password\n"
104
 
        "\t-q <query> - Query to run\n"
105
 
        "\t-v         - Increase verbosity level\n";
 
80
        "\t-P <pass>  - Password\n";
106
81
      return 1;
107
82
    }
108
83
  }
109
84
 
110
85
  drizzle::drizzle_c drizzle;
111
 
  drizzle_set_verbose(&drizzle.b_, verbose);
112
86
  drizzle::connection_c* con= new drizzle::connection_c(drizzle);
113
 
  if (mysql)
114
 
    drizzle_con_add_options(&con->b_, DRIZZLE_CON_MYSQL);
115
87
  con->set_tcp(host, port);
116
88
  con->set_auth(user, password);
117
 
  con->set_db(db);
 
89
  con->set_db("information_schema");
118
90
  drizzle::result_c result;
119
 
  if (con->query(result, query))
 
91
  drizzle::query_c q(*con, "select table_schema, table_name from tables where table_name like ?");
 
92
  q.p("%");
 
93
  cout << q.read() << endl;
 
94
  if (q.execute(result))
120
95
  {
121
96
    cerr << "query: " << con->error() << endl;
122
97
    return 1;