30
30
convert_decimal ,
31
31
convert_timedelta ,
32
32
unicase_compare ,
33
+ check_sqlite_table_xinfo_support ,
33
34
)
34
35
from .mysql_utils import (
35
36
MYSQL_BLOB_COLUMN_TYPES ,
@@ -157,6 +158,11 @@ def __init__(self, **kwargs):
157
158
158
159
self ._sqlite_cur = self ._sqlite .cursor ()
159
160
161
+ self ._sqlite_version = self ._get_sqlite_version ()
162
+ self ._sqlite_table_xinfo_support = check_sqlite_table_xinfo_support (
163
+ self ._sqlite_version
164
+ )
165
+
160
166
try :
161
167
self ._mysql = mysql .connector .connect (
162
168
user = self ._mysql_user ,
@@ -225,6 +231,17 @@ def _get_mysql_version(self):
225
231
)
226
232
raise
227
233
234
+ def _get_sqlite_version (self ):
235
+ try :
236
+ self ._sqlite_cur .execute ("SELECT sqlite_version()" )
237
+ return self ._sqlite_cur .fetchone ()[0 ]
238
+ except (IndexError , sqlite3 .Error ) as err :
239
+ self ._logger .error (
240
+ "SQLite failed checking for InnoDB version: %s" ,
241
+ err ,
242
+ )
243
+ raise
244
+
228
245
def _sqlite_table_has_rowid (self , table ):
229
246
try :
230
247
self ._sqlite_cur .execute ("""SELECT rowid FROM "{}" LIMIT 1""" .format (table ))
@@ -323,7 +340,14 @@ def _create_table(self, table_name, transfer_rowid=False):
323
340
if transfer_rowid :
324
341
sql += " `rowid` BIGINT NOT NULL, "
325
342
326
- self ._sqlite_cur .execute ('PRAGMA table_info("{}")' .format (table_name ))
343
+ self ._sqlite_cur .execute (
344
+ 'PRAGMA {command}("{table_name}")' .format (
345
+ command = "table_xinfo"
346
+ if self ._sqlite_table_xinfo_support
347
+ else "table_info" ,
348
+ table_name = table_name ,
349
+ )
350
+ )
327
351
328
352
rows = self ._sqlite_cur .fetchall ()
329
353
compound_primary_key = (
@@ -335,6 +359,12 @@ def _create_table(self, table_name, transfer_rowid=False):
335
359
mysql_safe_name = safe_identifier_length (column ["name" ])
336
360
column_type = self ._translate_type_from_sqlite_to_mysql (column ["type" ])
337
361
362
+ # The "hidden" value is 0 for visible columns, 1 for "hidden" columns,
363
+ # 2 for computed virtual columns and 3 for computed stored columns.
364
+ # Read more on hidden columns here https://www.sqlite.org/pragma.html#pragma_table_xinfo
365
+ if "hidden" in column and column ["hidden" ] == 1 :
366
+ continue
367
+
338
368
sql += " `{name}` {type} {notnull} {default} {auto_increment}, " .format (
339
369
name = mysql_safe_name ,
340
370
type = column_type ,
0 commit comments