368
368
com_nopager(string *str, const char*), com_pager(string *str, const char*);
370
370
static int read_and_execute(bool interactive);
371
static int sql_connect(const string &host, const string &database, const string &user, const string &password,
371
static int sql_connect(const string &host, const string &database, const string &user, const string &password);
373
372
static const char *server_version_string(drizzle_con_st *con);
374
373
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
375
374
const char *sql_state);
491
490
Commands( "tee", 'T', com_tee, 1,
492
491
N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
493
492
Commands( "use", 'u', com_use, 1,
494
N_("Use another database. Takes database name as argument.") ),
493
N_("Use another schema. Takes schema name as argument.") ),
495
494
Commands( "shutdown", 'u', com_shutdown, 1,
496
495
N_("Shutdown the instance you are connected too.") ),
497
496
Commands( "warnings", 'W', com_warnings, 0,
1683
1681
"This is free software,\n"
1684
1682
"and you are welcome to modify and redistribute it "
1685
1683
"under the GPL license\n"));
1686
printf(_("Usage: drizzle [OPTIONS] [database]\n"));
1684
printf(_("Usage: drizzle [OPTIONS] [schema]\n"));
1687
1685
cout << long_options;
1697
1695
memset(&drizzle, 0, sizeof(drizzle));
1698
if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent))
1696
if (sql_connect(current_host, current_db, current_user, opt_password))
1700
1698
quick= 1; // Avoid history
1701
1699
status.setExitStatus(1);
2537
2535
drizzle_return_t ret;
2538
2536
drizzle_result_st databases,tables,fields;
2539
2537
drizzle_row_t database_row,table_row;
2540
drizzle_column_st *sql_field;
2541
2538
string tmp_str, tmp_str_lower;
2543
2541
if (status.getBatch() || quick || current_db.empty())
2544
2542
return; // We don't need completion in batches
2558
2556
/* hash Drizzle functions (to be implemented) */
2560
2558
/* hash all database names */
2561
if (drizzle_query_str(&con, &databases, "show databases", &ret) != NULL)
2559
if (drizzle_query_str(&con, &databases, "select schema_name from information_schema.schemata", &ret) != NULL)
2563
2561
if (ret == DRIZZLE_RETURN_OK)
2578
2576
drizzle_result_free(&databases);
2581
/* hash all table names */
2582
if (drizzle_query_str(&con, &tables, "show tables", &ret) != NULL)
2579
query= "select table_name, column_name from information_schema.columns where table_schema='";
2580
query.append(current_db);
2581
query.append("' order by table_name");
2583
if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2584
if (ret != DRIZZLE_RETURN_OK)
2586
drizzle_result_free(&tables);
2590
if (drizzle_result_buffer(&tables) != DRIZZLE_RETURN_OK)
2591
put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
2586
if (ret == DRIZZLE_RETURN_OK &&
2587
drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
2594
2589
if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2599
2594
"You can turn off this feature to get a quicker "
2600
2595
"startup with -A\n\n"));
2602
while ((table_row=drizzle_row_next(&tables)))
2598
std::string table_name;
2599
while ((table_row=drizzle_row_next(&fields)))
2601
if (table_name.compare(table_row[0]) != 0)
2603
tmp_str= table_row[0];
2604
tmp_str_lower= lower_string(tmp_str);
2605
completion_map[tmp_str_lower]= tmp_str;
2606
table_name= table_row[0];
2604
2608
tmp_str= table_row[0];
2605
tmp_str_lower= lower_string(tmp_str);
2606
completion_map[tmp_str_lower]= tmp_str;
2613
/* hash all field names, both with the table prefix and without it */
2614
if (drizzle_result_row_count(&tables) == 0)
2616
drizzle_result_free(&tables);
2620
drizzle_row_seek(&tables, 0);
2622
while ((table_row=drizzle_row_next(&tables)))
2626
query.append("show fields in `");
2627
query.append(table_row[0]);
2630
if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2633
if (ret == DRIZZLE_RETURN_OK &&
2634
drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
2636
while ((sql_field=drizzle_column_next(&fields)))
2638
tmp_str=table_row[0];
2639
tmp_str.append(".");
2640
tmp_str.append(drizzle_column_name(sql_field));
2641
tmp_str_lower= lower_string(tmp_str);
2642
completion_map[tmp_str_lower]= tmp_str;
2644
tmp_str=drizzle_column_name(sql_field);
2645
tmp_str_lower= lower_string(tmp_str);
2646
completion_map[tmp_str_lower]= tmp_str;
2649
drizzle_result_free(&fields);
2652
drizzle_result_free(&tables);
2609
tmp_str.append(".");
2610
tmp_str.append(table_row[1]);
2611
tmp_str_lower= lower_string(tmp_str);
2612
completion_map[tmp_str_lower]= tmp_str;
2614
tmp_str= table_row[1];
2615
tmp_str_lower= lower_string(tmp_str);
2616
completion_map[tmp_str_lower]= tmp_str;
2620
drizzle_result_free(&fields);
2653
2621
completion_iter= completion_map.begin();
3728
error=sql_connect(current_host, current_db, current_user, opt_password,0);
3696
error=sql_connect(current_host, current_db, current_user, opt_password);
3729
3697
opt_rehash= save_rehash;
3733
3701
sprintf(buff, _("Connection id: %u"), drizzle_con_thread_id(&con));
3734
3702
put_info(buff,INFO_INFO,0,0);
3735
sprintf(buff, _("Current database: %.128s\n"),
3703
sprintf(buff, _("Current schema: %.128s\n"),
3736
3704
!current_db.empty() ? current_db.c_str() : _("*** NONE ***"));
3737
3705
put_info(buff,INFO_INFO,0,0);
3845
3813
tmp= get_arg(buff, 0);
3846
3814
if (!tmp || !*tmp)
3848
put_info(_("USE must be followed by a database name"), INFO_ERROR, 0, 0);
3816
put_info(_("USE must be followed by a schema name"), INFO_ERROR, 0, 0);
3913
3881
build_completion_hash(opt_rehash, 1);
3916
put_info(_("Database changed"),INFO_INFO, 0, 0);
3884
put_info(_("Schema changed"),INFO_INFO, 0, 0);
4037
sql_connect(const string &host, const string &database, const string &user, const string &password,
4005
sql_connect(const string &host, const string &database, const string &user, const string &password)
4040
4007
drizzle_return_t ret;
4085
4052
if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
4087
if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
4088
ret != DRIZZLE_RETURN_COULD_NOT_CONNECT))
4090
4057
(void) put_error(&con, NULL);
4091
4058
(void) fflush(stdout);
4130
4097
drizzle_row_t cur=drizzle_row_next(&result);
4133
tee_fprintf(stdout, _("Current database:\t%s\n"), cur[0] ? cur[0] : "");
4100
tee_fprintf(stdout, _("Current schema:\t%s\n"), cur[0] ? cur[0] : "");
4134
4101
tee_fprintf(stdout, _("Current user:\t\t%s\n"), cur[1]);
4136
4103
drizzle_result_free(&result);
4149
4116
if (skip_updates)
4151
4118
vidattr(A_BOLD);
4152
tee_fprintf(stdout, _("\nAll updates ignored to this database\n"));
4119
tee_fprintf(stdout, _("\nAll updates ignored to this schema\n"));
4153
4120
vidattr(A_NORMAL);
4155
4122
tee_fprintf(stdout, _("Current pager:\t\t%s\n"), pager.c_str());