test data test data - 29 days ago 7
MySQL Question

Why following query fails to do its job?




I had following the below queries to drop and create and insert but it throws an error?Is there any syntax error in the query which i used.

$DBH->do("USE rsdb_bangalore_current;");
$DBH->do("drop table rsdb_bangalore_current.queues;");
$DBH->do("create table rsdb_bangalore_current.queues(time int(11) not null,queue_name text,description text,priority int(11) not null,jobs_pending int(11) not null,jobs_running int(11) not null,lallot text,slots_used int(11),slots_free int(11),load_avg int(11), allowed_users text,machines text;");
$DBH->do( "INSERT INTO queues(time,queue_name,description,priority,jobs_pending,jobs_running,lallot,slots_used,slots_free,load_avg,allowed_users,machines) VALUES(\"$current_time\",\"$table_data{0}{'ENTRY'}\",\"$table_data{9}{'ENTRY'}\",\"$table_data{1}{'ENTRY'}\",\"$table_data{3}{'ENTRY'}\",\"$table_data{4}{'ENTRY'}\",\"$table_data{5}{'ENTRY'}\",\"$table_data{11}{'ENTRY'}\",\"$table_data{8}{'ENTRY'}\",\"$table_data{13}{'ENTRY'}\",\"$table_data{14}{'ENTRY'}\",\"$table_data{15}{'ENTRY'}\")");


Error occured:

DBD::mysql::db do failed: Table 'rsdb_bangalore_current.queues' doesn't exist


also occurs error for following queries:

$DBH->do("USE rsdb_bangalore_current;");
$DBH->do("drop table rsdb_bangalore_current.job_status;");
$DBH->do("create table rsdb_bangalore_current.job_status(time int(11) not null,job_type text,pending_qty int(11),running_qty int(11);");


Error occured:

DBD::mysql::db do failed: Unknown table 'job_status' at n1_rsdb.pl line 1100.
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 at n1_rsdb.pl line 1101.
DBD::mysql::db do failed: Table 'rsdb_bangalore_current.job_status' doesn't exist at n1_rsdb.pl line 1103.

Answer

There's a ) missing at the end of CREATE TABLE:

$DBH->do("create table rsdb_bangalore_current.queues(time int(11) not null,queue_name text,description text,priority int(11) not null,jobs_pending int(11) not null,jobs_running int(11) not null,lallot text,slots_used int(11),slots_free int(11),load_avg int(11), allowed_users text,machines text);");
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^

So the query would throw an error and wouldn't have created the table at all.