@@ -70,6 +70,8 @@ def __init__(self, **kwargs):
70
70
else (kwargs .get ("without_foreign_keys" ) or False )
71
71
)
72
72
73
+ self ._without_data = kwargs .get ("without_data" ) or False
74
+
73
75
self ._mysql_user = str (kwargs .get ("mysql_user" ))
74
76
75
77
self ._mysql_password = (
@@ -520,58 +522,68 @@ def transfer(self):
520
522
self ._sqlite_cur .execute ("PRAGMA foreign_keys=OFF" )
521
523
522
524
for table_name in tables :
525
+ self ._logger .info (
526
+ "%sTransferring table %s" ,
527
+ "[WITHOUT DATA] " if self ._without_data else "" ,
528
+ table_name ,
529
+ )
530
+
523
531
# reset the chunk
524
532
self ._current_chunk_number = 0
525
533
526
534
# create the table
527
535
self ._create_table (table_name )
528
536
529
- # get the size of the data
530
- if self ._limit_rows > 0 :
531
- # limit to the requested number of rows
532
- self ._mysql_cur_dict .execute (
533
- """
534
- SELECT COUNT(*) AS `total_records`
535
- FROM (SELECT * FROM `{table_name}` LIMIT {limit}) AS `table`
536
- """ .format (
537
- table_name = table_name , limit = self ._limit_rows
537
+ if not self ._without_data :
538
+ # get the size of the data
539
+ if self ._limit_rows > 0 :
540
+ # limit to the requested number of rows
541
+ self ._mysql_cur_dict .execute (
542
+ """
543
+ SELECT COUNT(*) AS `total_records`
544
+ FROM (SELECT * FROM `{table_name}` LIMIT {limit}) AS `table`
545
+ """ .format (
546
+ table_name = table_name , limit = self ._limit_rows
547
+ )
538
548
)
539
- )
540
- else :
541
- # get all rows
542
- self . _mysql_cur_dict . execute (
543
- "SELECT COUNT(*) AS `total_records` FROM `{ table_name}`" . format (
544
- table_name = table_name
549
+ else :
550
+ # get all rows
551
+ self . _mysql_cur_dict . execute (
552
+ "SELECT COUNT(*) AS `total_records` FROM `{table_name}`" . format (
553
+ table_name = table_name
554
+ )
545
555
)
556
+ total_records = int (
557
+ self ._mysql_cur_dict .fetchone ()["total_records" ]
546
558
)
547
- total_records = int (self ._mysql_cur_dict .fetchone ()["total_records" ])
548
-
549
- # only continue if there is anything to transfer
550
- if total_records > 0 :
551
- # populate it
552
- self ._logger .info ("Transferring table %s" , table_name )
553
- self ._mysql_cur .execute (
554
- "SELECT * FROM `{table_name}` {limit}" .format (
555
- table_name = table_name ,
556
- limit = "LIMIT {}" .format (self ._limit_rows )
557
- if self ._limit_rows > 0
558
- else "" ,
559
+
560
+ # only continue if there is anything to transfer
561
+ if total_records > 0 :
562
+ # populate it
563
+ self ._mysql_cur .execute (
564
+ "SELECT * FROM `{table_name}` {limit}" .format (
565
+ table_name = table_name ,
566
+ limit = "LIMIT {}" .format (self ._limit_rows )
567
+ if self ._limit_rows > 0
568
+ else "" ,
569
+ )
570
+ )
571
+ columns = [column [0 ] for column in self ._mysql_cur .description ]
572
+ # build the SQL string
573
+ sql = """
574
+ INSERT OR IGNORE
575
+ INTO "{table}" ({fields})
576
+ VALUES ({placeholders})
577
+ """ .format (
578
+ table = table_name ,
579
+ fields = ('"{}", ' * len (columns ))
580
+ .rstrip (" ," )
581
+ .format (* columns ),
582
+ placeholders = ("?, " * len (columns )).rstrip (" ," ),
583
+ )
584
+ self ._transfer_table_data (
585
+ table_name = table_name , sql = sql , total_records = total_records
559
586
)
560
- )
561
- columns = [column [0 ] for column in self ._mysql_cur .description ]
562
- # build the SQL string
563
- sql = """
564
- INSERT OR IGNORE
565
- INTO "{table}" ({fields})
566
- VALUES ({placeholders})
567
- """ .format (
568
- table = table_name ,
569
- fields = ('"{}", ' * len (columns )).rstrip (" ," ).format (* columns ),
570
- placeholders = ("?, " * len (columns )).rstrip (" ," ),
571
- )
572
- self ._transfer_table_data (
573
- table_name = table_name , sql = sql , total_records = total_records
574
- )
575
587
except Exception : # pylint: disable=W0706
576
588
raise
577
589
finally :
0 commit comments