~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Monty Taylor
  • Author(s): Andrew Hutchings
  • Date: 2011-02-21 13:59:06 UTC
  • mto: This revision was merged to the branch mainline in revision 2190.
  • Revision ID: andrew@linuxjedi.co.uk-20110221135906-mywndoq7oypdumya
Separate the server detection functions into a .h file
Include the new .h in drizzle to detect if we are connecting to drizzled
If we are connecting to drizzled output TRUE/FALSE for boolean

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <config.h>
38
38
#include <libdrizzle/drizzle_client.h>
39
39
 
40
 
#include <client/get_password.h>
 
40
#include "server_detect.h"
41
41
 
42
42
#include <boost/date_time/posix_time/posix_time.hpp>
43
43
 
307
307
static uint32_t select_limit;
308
308
static uint32_t max_join_size;
309
309
static uint32_t opt_connect_timeout= 0;
 
310
static ServerDetect::server_type server_type= ServerDetect::SERVER_UNKNOWN_FOUND;
310
311
std::string current_db,
311
312
  delimiter_str,  
312
313
  current_host,
3128
3129
  drizzle_return_t ret;
3129
3130
  drizzle_column_st *field;
3130
3131
  std::vector<bool> num_flag;
 
3132
  std::vector<bool> boolean_flag;
3131
3133
  string separator;
3132
3134
 
3133
3135
  separator.reserve(256);
3134
3136
 
3135
3137
  num_flag.resize(drizzle_result_column_count(result));
 
3138
  boolean_flag.resize(drizzle_result_column_count(result));
3136
3139
  if (column_types_flag)
3137
3140
  {
3138
3141
    print_field_types(result);
3175
3178
      // Room for "NULL"
3176
3179
      length=4;
3177
3180
    }
 
3181
    if ((length < 5) and 
 
3182
      (server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
 
3183
      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
 
3184
    {
 
3185
      // Room for "FALSE"
 
3186
      length= 5;
 
3187
    }
3178
3188
    drizzle_column_set_max_size(field, length);
3179
3189
 
3180
3190
    for (x=0; x< (length+2); x++)
3198
3208
                  drizzle_column_name(field));
3199
3209
      num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||
3200
3210
                      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));
 
3211
      if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
 
3212
        (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
 
3213
      {
 
3214
        boolean_flag[off]= true;
 
3215
        num_flag[off]= false;
 
3216
      }
 
3217
      else
 
3218
      {
 
3219
        boolean_flag[off]= false;
 
3220
      }
3201
3221
    }
3202
3222
    (void) tee_fputs("\n", PAGER);
3203
3223
    tee_puts((char*) separator.c_str(), PAGER);
3236
3256
        buffer= "NULL";
3237
3257
        data_length= 4;
3238
3258
      }
 
3259
      else if (boolean_flag[off])
 
3260
      {
 
3261
        if (strncmp(cur[off],"1", 1) == 0)
 
3262
        {
 
3263
          buffer= "TRUE";
 
3264
          data_length= 4;
 
3265
        }
 
3266
        else
 
3267
        {
 
3268
          buffer= "FALSE";
 
3269
          data_length= 5;
 
3270
        }
 
3271
      }
3239
3272
      else
3240
3273
      {
3241
3274
        buffer= cur[off];
4108
4141
  }
4109
4142
  connected=1;
4110
4143
 
 
4144
  ServerDetect server_detect(&con);
 
4145
  server_type= server_detect.getServerType();
 
4146
 
4111
4147
  build_completion_hash(opt_rehash, 1);
4112
4148
  return 0;
4113
4149
}