@@ -386,7 +386,7 @@ static struct my_option my_long_options[] =
386
386
(gptr * ) & opt_dump_triggers , (gptr * ) & opt_dump_triggers , 0 , GET_BOOL ,
387
387
NO_ARG , 1 , 0 , 0 , 0 , 0 , 0 },
388
388
{"tz-utc" , OPT_TZ_UTC ,
389
- "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data between servers with different time zones." ,
389
+ "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones." ,
390
390
(gptr * ) & opt_tz_utc , (gptr * ) & opt_tz_utc , 0 , GET_BOOL , NO_ARG , 1 , 0 , 0 , 0 , 0 , 0 },
391
391
#ifndef DONT_ALLOW_USER_CHANGE
392
392
{"user" , 'u' , "User for login if not current user." ,
@@ -1328,17 +1328,17 @@ static uint dump_routines_for_db(char *db)
1328
1328
static uint get_table_structure (char * table , char * db , char * table_type ,
1329
1329
char * ignore_flag )
1330
1330
{
1331
- MYSQL_RES * tableRes ;
1332
- MYSQL_ROW row ;
1333
1331
my_bool init = 0 , delayed , write_data , complete_insert ;
1334
- uint num_fields ;
1332
+ my_ulonglong num_fields ;
1335
1333
char * result_table , * opt_quoted_table ;
1336
1334
const char * insert_option ;
1337
1335
char name_buff [NAME_LEN + 3 ],table_buff [NAME_LEN * 2 + 3 ];
1338
- char table_buff2 [NAME_LEN * 2 + 3 ];
1339
- char query_buff [512 ];
1336
+ char table_buff2 [NAME_LEN * 2 + 3 ], query_buff [512 ];
1340
1337
FILE * sql_file = md_result_file ;
1341
1338
int len ;
1339
+ MYSQL_RES * result ;
1340
+ MYSQL_ROW row ;
1341
+
1342
1342
DBUG_ENTER ("get_table_structure" );
1343
1343
DBUG_PRINT ("enter" , ("db: %s table: %s" , db , table ));
1344
1344
@@ -1424,71 +1424,79 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1424
1424
check_io (sql_file );
1425
1425
}
1426
1426
1427
- tableRes = mysql_store_result (sock );
1428
- field = mysql_fetch_field_direct (tableRes , 0 );
1427
+ result = mysql_store_result (sock );
1428
+ field = mysql_fetch_field_direct (result , 0 );
1429
1429
if (strcmp (field -> name , "View" ) == 0 )
1430
1430
{
1431
1431
if (verbose )
1432
1432
fprintf (stderr , "-- It's a view, create dummy table for view\n" );
1433
1433
1434
- mysql_free_result (tableRes );
1434
+ mysql_free_result (result );
1435
1435
1436
- /* Create a dummy table for the view. ie. a table which has the
1437
- same columns as the view should have. This table is dropped
1438
- just before the view is created. The table is used to handle the
1439
- case where a view references another view, which hasn't yet been
1440
- created(during the load of the dump). BUG#10927 */
1436
+ /*
1437
+ Create a table with the same name as the view and with columns of
1438
+ the same name in order to satisfy views that depend on this view.
1439
+ The table will be removed when the actual view is created.
1441
1440
1442
- /* Create temp table by selecting from the view */
1441
+ The properties of each column, aside from the data type, are not
1442
+ preserved in this temporary table, because they are not necessary.
1443
+
1444
+ This will not be necessary once we can determine dependencies
1445
+ between views and can simply dump them in the appropriate order.
1446
+ */
1443
1447
my_snprintf (query_buff , sizeof (query_buff ),
1444
- "CREATE TEMPORARY TABLE %s SELECT * FROM %s WHERE 0" ,
1445
- result_table , result_table );
1448
+ "SHOW FIELDS FROM %s" , result_table );
1446
1449
if (mysql_query_with_error_report (sock , 0 , query_buff ))
1447
1450
{
1448
1451
safe_exit (EX_MYSQLERR );
1449
1452
DBUG_RETURN (0 );
1450
1453
}
1451
1454
1452
- /* Get CREATE statement for the temp table */
1453
- my_snprintf (query_buff , sizeof (query_buff ), "SHOW CREATE TABLE %s" ,
1454
- result_table );
1455
- if (mysql_query_with_error_report (sock , 0 , query_buff ))
1455
+ if ((result = mysql_store_result (sock )))
1456
1456
{
1457
- safe_exit (EX_MYSQLERR );
1458
- DBUG_RETURN (0 );
1459
- }
1460
- tableRes = mysql_store_result (sock );
1461
- row = mysql_fetch_row (tableRes );
1462
-
1463
- if (opt_drop )
1464
- fprintf (sql_file , "/*!50001 DROP VIEW IF EXISTS %s*/;\n" ,
1465
- opt_quoted_table );
1466
-
1467
- /* Print CREATE statement but remove TEMPORARY */
1468
- fprintf (sql_file , "/*!50001 CREATE %s*/;\n" , row [1 ]+ 17 );
1469
- check_io (sql_file );
1470
-
1471
- mysql_free_result (tableRes );
1457
+ if (mysql_num_rows (result ))
1458
+ {
1459
+ if (opt_drop )
1460
+ {
1461
+ fprintf (sql_file , "/*!50001 DROP VIEW IF EXISTS %s*/;\n" ,
1462
+ opt_quoted_table );
1463
+ check_io (sql_file );
1464
+ }
1472
1465
1473
- /* Drop the temp table */
1474
- my_snprintf (buff , sizeof (buff ),
1475
- "DROP TEMPORARY TABLE %s" , result_table );
1476
- if (mysql_query_with_error_report (sock , 0 , buff ))
1477
- {
1478
- safe_exit (EX_MYSQLERR );
1479
- DBUG_RETURN (0 );
1466
+ fprintf (sql_file , "/*!50001 CREATE TABLE %s (\n" , result_table );
1467
+ /*
1468
+ Get first row, following loop will prepend comma - keeps
1469
+ from having to know if the row being printed is last to
1470
+ determine if there should be a _trailing_ comma.
1471
+ */
1472
+ row = mysql_fetch_row (result );
1473
+
1474
+ fprintf (sql_file , " %s %s" , quote_name (row [0 ], name_buff , 0 ), row [1 ]);
1475
+
1476
+ while ((row = mysql_fetch_row (result )))
1477
+ {
1478
+ /* col name, col type */
1479
+ fprintf (sql_file , ",\n %s %s" ,
1480
+ quote_name (row [0 ], name_buff , 0 ), row [1 ]);
1481
+ }
1482
+ fprintf (sql_file , "\n) */;\n" );
1483
+ check_io (sql_file );
1484
+ }
1480
1485
}
1486
+ mysql_free_result (result );
1487
+
1481
1488
was_views = 1 ;
1482
1489
DBUG_RETURN (0 );
1483
1490
}
1484
- row = mysql_fetch_row (tableRes );
1491
+
1492
+ row = mysql_fetch_row (result );
1485
1493
fprintf (sql_file , "%s;\n" , row [1 ]);
1486
1494
check_io (sql_file );
1487
- mysql_free_result (tableRes );
1495
+ mysql_free_result (result );
1488
1496
}
1489
1497
my_snprintf (query_buff , sizeof (query_buff ), "show fields from %s" ,
1490
1498
result_table );
1491
- if (mysql_query_with_error_report (sock , & tableRes , query_buff ))
1499
+ if (mysql_query_with_error_report (sock , & result , query_buff ))
1492
1500
{
1493
1501
if (path )
1494
1502
my_fclose (sql_file , MYF (MY_WME ));
@@ -1520,7 +1528,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1520
1528
}
1521
1529
}
1522
1530
1523
- while ((row = mysql_fetch_row (tableRes )))
1531
+ while ((row = mysql_fetch_row (result )))
1524
1532
{
1525
1533
if (complete_insert )
1526
1534
{
@@ -1533,8 +1541,8 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1533
1541
quote_name (row [SHOW_FIELDNAME ], name_buff , 0 ));
1534
1542
}
1535
1543
}
1536
- num_fields = ( uint ) mysql_num_rows (tableRes );
1537
- mysql_free_result (tableRes );
1544
+ num_fields = mysql_num_rows (result );
1545
+ mysql_free_result (result );
1538
1546
}
1539
1547
else
1540
1548
{
@@ -1545,7 +1553,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1545
1553
1546
1554
my_snprintf (query_buff , sizeof (query_buff ), "show fields from %s" ,
1547
1555
result_table );
1548
- if (mysql_query_with_error_report (sock , & tableRes , query_buff ))
1556
+ if (mysql_query_with_error_report (sock , & result , query_buff ))
1549
1557
{
1550
1558
safe_exit (EX_MYSQLERR );
1551
1559
DBUG_RETURN (0 );
@@ -1595,9 +1603,9 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1595
1603
}
1596
1604
}
1597
1605
1598
- while ((row = mysql_fetch_row (tableRes )))
1606
+ while ((row = mysql_fetch_row (result )))
1599
1607
{
1600
- ulong * lengths = mysql_fetch_lengths (tableRes );
1608
+ ulong * lengths = mysql_fetch_lengths (result );
1601
1609
if (init )
1602
1610
{
1603
1611
if (!opt_xml && !tFlag )
@@ -1616,7 +1624,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1616
1624
{
1617
1625
if (opt_xml )
1618
1626
{
1619
- print_xml_row (sql_file , "field" , tableRes , & row );
1627
+ print_xml_row (sql_file , "field" , result , & row );
1620
1628
continue ;
1621
1629
}
1622
1630
@@ -1640,15 +1648,15 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1640
1648
check_io (sql_file );
1641
1649
}
1642
1650
}
1643
- num_fields = ( uint ) mysql_num_rows (tableRes );
1644
- mysql_free_result (tableRes );
1651
+ num_fields = mysql_num_rows (result );
1652
+ mysql_free_result (result );
1645
1653
if (!tFlag )
1646
1654
{
1647
1655
/* Make an sql-file, if path was given iow. option -T was given */
1648
1656
char buff [20 + FN_REFLEN ];
1649
1657
uint keynr ,primary_key ;
1650
1658
my_snprintf (buff , sizeof (buff ), "show keys from %s" , result_table );
1651
- if (mysql_query_with_error_report (sock , & tableRes , buff ))
1659
+ if (mysql_query_with_error_report (sock , & result , buff ))
1652
1660
{
1653
1661
if (mysql_errno (sock ) == ER_WRONG_OBJECT )
1654
1662
{
@@ -1667,7 +1675,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1667
1675
/* Find first which key is primary key */
1668
1676
keynr = 0 ;
1669
1677
primary_key = INT_MAX ;
1670
- while ((row = mysql_fetch_row (tableRes )))
1678
+ while ((row = mysql_fetch_row (result )))
1671
1679
{
1672
1680
if (atoi (row [3 ]) == 1 )
1673
1681
{
@@ -1683,13 +1691,13 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1683
1691
}
1684
1692
}
1685
1693
}
1686
- mysql_data_seek (tableRes ,0 );
1694
+ mysql_data_seek (result ,0 );
1687
1695
keynr = 0 ;
1688
- while ((row = mysql_fetch_row (tableRes )))
1696
+ while ((row = mysql_fetch_row (result )))
1689
1697
{
1690
1698
if (opt_xml )
1691
1699
{
1692
- print_xml_row (sql_file , "key" , tableRes , & row );
1700
+ print_xml_row (sql_file , "key" , result , & row );
1693
1701
continue ;
1694
1702
}
1695
1703
@@ -1730,7 +1738,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1730
1738
my_snprintf (buff , sizeof (buff ), "show table status like %s" ,
1731
1739
quote_for_like (table , show_name_buff ));
1732
1740
1733
- if (mysql_query_with_error_report (sock , & tableRes , buff ))
1741
+ if (mysql_query_with_error_report (sock , & result , buff ))
1734
1742
{
1735
1743
if (mysql_errno (sock ) != ER_PARSE_ERROR )
1736
1744
{ /* If old MySQL version */
@@ -1740,7 +1748,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1740
1748
result_table ,mysql_error (sock ));
1741
1749
}
1742
1750
}
1743
- else if (!(row = mysql_fetch_row (tableRes )))
1751
+ else if (!(row = mysql_fetch_row (result )))
1744
1752
{
1745
1753
fprintf (stderr ,
1746
1754
"Error: Couldn't read status information for table %s (%s)\n" ,
@@ -1749,18 +1757,18 @@ static uint get_table_structure(char *table, char *db, char *table_type,
1749
1757
else
1750
1758
{
1751
1759
if (opt_xml )
1752
- print_xml_row (sql_file , "options" , tableRes , & row );
1760
+ print_xml_row (sql_file , "options" , result , & row );
1753
1761
else
1754
1762
{
1755
1763
fputs ("/*!" ,sql_file );
1756
- print_value (sql_file ,tableRes ,row ,"engine=" ,"Engine" ,0 );
1757
- print_value (sql_file ,tableRes ,row ,"" ,"Create_options" ,0 );
1758
- print_value (sql_file ,tableRes ,row ,"comment=" ,"Comment" ,1 );
1764
+ print_value (sql_file ,result ,row ,"engine=" ,"Engine" ,0 );
1765
+ print_value (sql_file ,result ,row ,"" ,"Create_options" ,0 );
1766
+ print_value (sql_file ,result ,row ,"comment=" ,"Comment" ,1 );
1759
1767
fputs (" */" ,sql_file );
1760
1768
check_io (sql_file );
1761
1769
}
1762
1770
}
1763
- mysql_free_result (tableRes ); /* Is always safe to free */
1771
+ mysql_free_result (result ); /* Is always safe to free */
1764
1772
}
1765
1773
continue_xml :
1766
1774
if (!opt_xml )
@@ -1827,7 +1835,7 @@ static void dump_triggers_for_table (char *table, char *db)
1827
1835
if (mysql_num_rows (result ))
1828
1836
fprintf (sql_file , "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n\
1829
1837
DELIMITER ;;\n" );
1830
- while ((row = mysql_fetch_row (result )))
1838
+ while ((row = mysql_fetch_row (result )))
1831
1839
{
1832
1840
fprintf (sql_file , "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n\
1833
1841
/*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s */;;\n\n" ,
@@ -2119,10 +2127,10 @@ static void dump_table(char *table, char *db)
2119
2127
check_io (md_result_file );
2120
2128
}
2121
2129
2122
- while ((row = mysql_fetch_row (res )))
2130
+ while ((row = mysql_fetch_row (res )))
2123
2131
{
2124
2132
uint i ;
2125
- ulong * lengths = mysql_fetch_lengths (res );
2133
+ ulong * lengths = mysql_fetch_lengths (res );
2126
2134
rownr ++ ;
2127
2135
if (!extended_insert && !opt_xml )
2128
2136
{
0 commit comments