Skip to content

Commit 429f4b6

Browse files
authored
Merge pull request mysql2sqlite#34 from ibukanov/master
fix escaping of seqences of even number of backslashes
2 parents cd734c7 + 06bfe9d commit 429f4b6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

mysql2sqlite

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,21 @@ inView != 0 { next }
103103
# print all INSERT lines
104104
( /^ *\(/ && /\) *[,;] *$/ ) || /^(INSERT|insert)/ {
105105
prev = ""
106+
107+
# first replace \\ by \_ that mysqldump never generates to deal with
108+
# sequnces like \\n that should be translated into \n, not \<LF>.
109+
# After we convert all escapes we replace \_ by backslashes.
110+
gsub( /\\\\/, "\\_" )
111+
106112
# single quotes are escaped by another single quote
107113
gsub( /\\'/, "''" )
108-
gsub( /\\'',/, "\\'," )
109114
gsub( /\\n/, "\n" )
110115
gsub( /\\r/, "\r" )
111116
gsub( /\\"/, "\"" )
112-
gsub( /\\\\/, "\\" )
113117
gsub( /\\\032/, "\032" ) # substitute char
118+
119+
gsub( /\\_/, "\\" )
120+
114121
# sqlite3 is limited to 16 significant digits of precision
115122
while( match( $0, /0x[0-9a-fA-F]{17}/ ) ){
116123
hexIssue = 1
@@ -221,8 +228,8 @@ aInc == 1 && /PRIMARY KEY|primary key/ { next }
221228
print ");"
222229
next
223230
}
224-
# `KEY` lines are extracted from the `CREATE` block and stored in array for later print
225-
# in a separate `CREATE KEY` command. The index name is prefixed by the table name to
231+
# `KEY` lines are extracted from the `CREATE` block and stored in array for later print
232+
# in a separate `CREATE KEY` command. The index name is prefixed by the table name to
226233
# avoid a sqlite error for duplicate index name.
227234
/^( (KEY|key)|\);)/ {
228235
if( prev ){

0 commit comments

Comments
 (0)