@@ -35,13 +35,14 @@ const SQLTYPES = Dict{Type, String}(
3535
3636checkdupnames (names) = length (unique (map (x-> lowercase (String (x)), names))) == length (names) || error (" duplicate case-insensitive column names detected; sqlite doesn't allow duplicate column names and treats them case insensitive" )
3737
38- function createtable (conn:: Connection , nm:: AbstractString , sch:: Tables.Schema ; debug:: Bool = false , quoteidentifiers:: Bool = true , createtableclause:: AbstractString = " CREATE TABLE" , coltypes= Dict (), columnsuffix= Dict ())
38+ function createtable (conn:: Connection , nm:: AbstractString , sch:: Tables.Schema ; debug:: Bool = false , quoteidentifiers:: Bool = true , createtableclause:: AbstractString = " CREATE TABLE" , coltypes= Dict (), columnsuffix= Dict (), auto_increment_primary_key_name :: Union{Nothing,AbstractString} = nothing )
3939 names = sch. names
4040 checkdupnames (names)
4141 types = [sqltype (T, coltypes, names[i]) for (i, T) in enumerate (sch. types)]
4242 columns = (string (quoteidentifiers ? quoteid (String (names[i])) : names[i], ' ' , types[i], ' ' , get (columnsuffix, names[i], " " )) for i = 1 : length (names))
43- debug && @info " executing create table statement: `$createtableclause $nm ($(join (columns, " , " )) )`"
44- return DBInterface. execute (conn, " $createtableclause $nm ($(join (columns, " , " )) )" )
43+ auto_increment_column = (auto_increment_primary_key_name === nothing || isempty (auto_increment_primary_key_name)) ? " " : " $(auto_increment_primary_key_name) INT AUTO_INCREMENT PRIMARY KEY, "
44+ debug && @info " executing create table statement: `$createtableclause $nm ($(auto_increment_column)$(join (columns, " , " )) )`"
45+ return DBInterface. execute (conn, " $createtableclause $nm ($(auto_increment_column)$(join (columns, " , " )) )" )
4546end
4647
4748"""
@@ -97,7 +98,7 @@ function load(itr, conn::Connection, name::AbstractString="mysql_"*Random.randst
9798 # start a transaction for inserting rows
9899 DBInterface. transaction (conn) do
99100 params = chop (repeat (" ?," , length (sch. names)))
100- stmt = DBInterface. prepare (conn, " INSERT INTO $name VALUES ($params )" )
101+ stmt = DBInterface. prepare (conn, " INSERT INTO $name ( $( join (sch . names .| > string .| > quoteid, " , " )) ) VALUES ($params )" )
101102 for (i, row) in enumerate (rows)
102103 i > limit && break
103104 debug && @info " inserting row $i ; $(Tables. Row (row)) "
0 commit comments