Commit 2db1639c authored by unknown's avatar unknown

Merge serg@work:/home/bk/mysql

into serg.mysql.com:/usr/home/serg/Abk/mysql

parents b0f645e4 76a09831
......@@ -594,7 +594,88 @@ static uint getTableStructure(char *table, char* db)
if (verbose)
fprintf(stderr, "# Retrieving table structure for table %s...\n", table);
sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", opt_quoted);
table_name=quote_name(table,table_buff);
if (mysql_query(sock,insert_pat))
{
/* using SHOW CREATE statement */
if (!tFlag)
{
/* Make an sql-file, if path was given iow. option -T was given */
char buff[20+FN_REFLEN];
sprintf(buff,"show create table %s",table_name);
if (mysql_query(sock, buff))
{
fprintf(stderr, "%s: Can't get CREATE TABLE for table '%s' (%s)\n",
my_progname, table, mysql_error(sock));
safe_exit(EX_MYSQLERR);
DBUG_RETURN(0);
}
if (path)
{
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
strmov(tmp_path,path);
convert_dirname(tmp_path);
sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
O_WRONLY, MYF(MY_WME));
if (!sql_file) /* If file couldn't be opened */
{
safe_exit(EX_MYSQLERR);
DBUG_RETURN(0);
}
write_heder(sql_file, db);
}
fprintf(sql_file, "\n#\n# Table structure for table '%s'\n#\n\n", table);
if (opt_drop)
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",table_name);
tableRes=mysql_store_result(sock);
row=mysql_fetch_row(tableRes);
fprintf(sql_file, "%s;\n", row[1]);
mysql_free_result(tableRes);
}
sprintf(insert_pat,"show fields from %s",table_name);
if (mysql_query(sock,insert_pat) || !(tableRes=mysql_store_result(sock)))
{
fprintf(stderr, "%s: Can't get info about table: '%s'\nerror: %s\n",
my_progname, table, mysql_error(sock));
safe_exit(EX_MYSQLERR);
DBUG_RETURN(0);
}
if (cFlag)
sprintf(insert_pat, "INSERT %sINTO %s (", delayed, table_name);
else
{
sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, table_name);
if (!extended_insert)
strcat(insert_pat,"(");
}
strpos=strend(insert_pat);
while ((row=mysql_fetch_row(tableRes)))
{
ulong *lengths=mysql_fetch_lengths(tableRes);
if (init)
{
if (cFlag)
strpos=strmov(strpos,", ");
}
init=1;
if (cFlag)
strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME],name_buff));
}
numFields = (uint) mysql_num_rows(tableRes);
mysql_free_result(tableRes);
}
else
{
/* fprintf(stderr, "%s: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
my_progname, mysql_error(sock)); */
sprintf(insert_pat,"show fields from %s",table_name);
if (mysql_query(sock,insert_pat) || !(tableRes=mysql_store_result(sock)))
{
......@@ -695,10 +776,10 @@ static uint getTableStructure(char *table, char* db)
if (atoi(row[3]) == 1)
{
keynr++;
#ifdef FORCE_PRIMARY_KEY
#ifdef FORCE_PRIMARY_KEY
if (atoi(row[1]) == 0 && primary_key == INT_MAX)
primary_key=keynr;
#endif
#endif
if (!strcmp(row[2],"PRIMARY"))
{
primary_key=keynr;
......@@ -765,6 +846,7 @@ static uint getTableStructure(char *table, char* db)
}
fputs(";\n", sql_file);
}
}
if (cFlag)
{
strpos=strmov(strpos,") VALUES ");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment