You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stmt = DBInterface.prepare(conn, "INSERT INTO test_table VALUES(?, ?)") # prepare a statement with positional parameters
32
32
33
-
DBInterface.execute!(stmt, 1, 3.14) # execute the prepared INSERT statement, passing 1 and 3.14 as positional parameters
33
+
DBInterface.execute(stmt, [1, 3.14]) # execute the prepared INSERT statement, passing 1 and 3.14 as positional parameters
34
34
35
35
stmt = DBInterface.prepare(conn, "INSERT INTO test_table VALUES(:col1, :col2)") # prepare a statement with named parameters
36
36
37
-
DBInterface.execute!(stmt; col1=1, col2=3.14) # execute the prepared INSERT statement, with 1 and 3.14 as named parameters
37
+
DBInterface.execute(stmt, (col1=1, col2=3.14)) # execute the prepared INSERT statement, with 1 and 3.14 as named parameters
38
38
39
-
DBInterface.executemany!(stmt; col1=[1,2,3,4,5], col2=[3.14, 1.23, 2.343.45, 4.56]) # execute the prepared statement multiple times for each set of named parameters; each named parameter must be an indexable collection
39
+
DBInterface.executemany(stmt, (col1=[1,2,3,4,5], col2=[3.14, 1.23, 2.343.45, 4.56])) # execute the prepared statement multiple times for each set of named parameters; each named parameter must be an indexable collection
40
+
41
+
DBInterface.close!(stmt) # close the prepared statement
Copy file name to clipboardExpand all lines: src/DBInterface.jl
+43-31Lines changed: 43 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -53,64 +53,76 @@ macro prepare(getDB, sql)
53
53
key =gensym()
54
54
returnquote
55
55
get!(DBInterface.PREPARED_STMTS, $(QuoteNode(key))) do
56
-
println("preparing stmt")
57
56
DBInterface.prepare($(esc(getDB)), $sql)
58
57
end
59
58
end
60
59
end
61
60
62
-
"Any object that iterates \"rows\", which are objects that are property-accessible and indexable. See `DBInterface.execute!` for more details on fetching query results."
61
+
"Any object that iterates \"rows\", which are objects that are property-accessible and indexable. See `DBInterface.execute` for more details on fetching query results."
all(x ->length(x) == len, args) ||throw(ParameterError("positional parameters provided to `DBInterface.executemany!` do not all have the same number of parameters"))
95
-
for i =1:len
96
-
xargs =map(x -> x[i], args)
97
-
execute!(stmt, xargs...)
98
-
end
99
-
elseif!isempty(kw)
100
-
k = kw[1]
101
-
len =length(k)
102
-
all(x ->length(x) == len, kw) ||throw(ParameterError("named parameters provided to `DBInterface.executemany!` do not all have the same number of parameters"))
103
+
functionexecutemany(stmt::Statement, params=())
104
+
if!isempty(params)
105
+
param = params[1]
106
+
len =length(param)
107
+
all(x ->length(x) == len, params) ||throw(ParameterError("parameters provided to `DBInterface.executemany!` do not all have the same number of parameters"))
0 commit comments