~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/client.cc

  • Committer: Brian Aker
  • Date: 2011-11-24 03:44:17 UTC
  • mto: This revision was merged to the branch mainline in revision 2465.
  • Revision ID: brian@tangent.org-20111124034417-aafezwidyzjhg6a3
Redo the way options are handled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
        client.level= BUFFER_ALL;
133
133
      else
134
134
      {
135
 
        printf("Invalid buffer level: %s\n", optarg);
 
135
        fprintf(stderr, "Invalid buffer level: %s\n", optarg);
136
136
        exit(0);
137
137
      }
138
138
      break;
198
198
                                                    sizeof(client_con_st));
199
199
    if (client.client_con_list == NULL)
200
200
    {
201
 
      printf("calloc:%d\n", errno);
 
201
      fprintf(stderr, "calloc:%d\n", errno);
202
202
      exit(1);
203
203
    }
204
204
  }
206
206
  /* This may fail if there is other initialization that fails. See docs. */
207
207
  if ((client.drizzle= drizzle_create()) == NULL)
208
208
  {
209
 
    printf("drizzle_create failed\n");
 
209
    fprintf(stderr, "drizzle_create failed\n");
210
210
    exit(1);
211
211
  }
212
212
 
213
213
  if (blocking == 0)
214
214
  {
215
 
    drizzle_add_options(client.drizzle, DRIZZLE_NON_BLOCKING);
 
215
    drizzle_set_option(client.drizzle, DRIZZLE_NON_BLOCKING, true);
216
216
  }
217
217
 
218
218
  /* Start all connections, and if in non-blocking mode, return as soon as the
333
333
        column= drizzle_column_read(&(client_con->result),
334
334
                                    &(client_con->column), &ret);
335
335
        if (ret == DRIZZLE_RETURN_IO_WAIT)
 
336
        {
336
337
          return 1;
 
338
        }
337
339
        else if (ret != DRIZZLE_RETURN_OK)
 
340
        {
338
341
          CLIENT_ERROR("drizzle_column_read", ret, client);
 
342
        }
339
343
 
340
344
        if (column == NULL)
341
345
          break;
355
359
      {
356
360
        field_sizes= drizzle_row_field_sizes(&(client_con->result));
357
361
 
358
 
        printf("Row: %" PRId64 "\n",
359
 
               drizzle_row_current(&(client_con->result)));
 
362
        printf("Row: %" PRId64 "\n", drizzle_row_current(&(client_con->result)));
360
363
 
361
364
        for (x= 0; x < drizzle_result_column_count(&(client_con->result)); x++)
362
365
        {
363
366
          if (row[x] == NULL)
 
367
          {
364
368
            printf("     (NULL)\n");
 
369
          }
365
370
          else
366
371
          {
367
 
            printf("     (%"PRIu64") %.*s\n", static_cast<uint64_t>(field_sizes[x]), (int32_t)field_sizes[x],
368
 
                   row[x]);
 
372
            printf("     (%"PRIu64") %.*s\n", static_cast<uint64_t>(field_sizes[x]), (int32_t)field_sizes[x], row[x]);
369
373
          }
370
374
        }
371
375
 
424
428
            CLIENT_ERROR("drizzle_field_read", ret, client);
425
429
 
426
430
          if (field == NULL)
 
431
          {
427
432
            printf("     (NULL)");
 
433
          }
428
434
          else if (offset > 0)
 
435
          {
429
436
            printf("%.*s", (int32_t)length, field);
 
437
          }
430
438
          else
431
 
            printf("     (%" PRIu64 " %.*s", (uint64_t)total,
432
 
                            (int32_t)length, field);
 
439
          {
 
440
            printf("     (%" PRIu64 " %.*s", (uint64_t)total, (int32_t)length, field);
 
441
          }
433
442
 
434
443
          if (offset + length == total)
 
444
          {
435
445
            printf("\n");
 
446
          }
436
447
 
437
448
          /* If we buffered the entire field, be sure to free it. */
438
449
          if (client->level == BUFFER_FIELD)