@@ -297,6 +297,73 @@ defmodule Exqlite.Sqlite3Test do
297
297
end
298
298
end
299
299
300
+ describe ".bind_text/3" do
301
+ setup do
302
+ { :ok , conn } = Sqlite3 . open ( ":memory:" , [ :readonly ] )
303
+ { :ok , stmt } = Sqlite3 . prepare ( conn , "select ?" )
304
+ { :ok , conn: conn , stmt: stmt }
305
+ end
306
+
307
+ test "binds text value" , % { conn: conn , stmt: stmt } do
308
+ assert :ok = Sqlite3 . bind_text ( stmt , 1 , "hello" )
309
+ assert { :row , [ "hello" ] } = Sqlite3 . step ( conn , stmt )
310
+ end
311
+
312
+ test "binds emojis" , % { conn: conn , stmt: stmt } do
313
+ assert :ok = Sqlite3 . bind_text ( stmt , 1 , "hello 👋 world 🌏" )
314
+ assert { :row , [ "hello 👋 world 🌏" ] } = Sqlite3 . step ( conn , stmt )
315
+ end
316
+
317
+ test "errors on invalid statement" do
318
+ assert_raise ArgumentError , "argument error: nil" , fn ->
319
+ Sqlite3 . bind_text ( _not_stmt = nil , 1 , "hello" )
320
+ end
321
+ end
322
+
323
+ test "errors on invalid index" , % { stmt: stmt } do
324
+ assert_raise Exqlite.Error , "column index out of range" , fn ->
325
+ Sqlite3 . bind_text ( stmt , _out_of_range = 2 , "hello" )
326
+ end
327
+ end
328
+
329
+ test "errors on invalid text argument" , % { stmt: stmt } do
330
+ assert_raise ArgumentError , "argument error: 1" , fn ->
331
+ Sqlite3 . bind_text ( stmt , 1 , _not_text = 1 )
332
+ end
333
+ end
334
+ end
335
+
336
+ describe ".bind_blob/3" do
337
+ setup do
338
+ { :ok , conn } = Sqlite3 . open ( ":memory:" , [ :readonly ] )
339
+ { :ok , stmt } = Sqlite3 . prepare ( conn , "select ?" )
340
+ { :ok , conn: conn , stmt: stmt }
341
+ end
342
+
343
+ test "binds binary value" , % { conn: conn , stmt: stmt } do
344
+ assert :ok = Sqlite3 . bind_blob ( stmt , 1 , << 0 , 0 , 0 >> )
345
+ assert { :row , [ << 0 , 0 , 0 >> ] } = Sqlite3 . step ( conn , stmt )
346
+ end
347
+
348
+ test "errors on invalid statement" do
349
+ assert_raise ArgumentError , "argument error: nil" , fn ->
350
+ Sqlite3 . bind_blob ( _not_stmt = nil , 1 , "hello" )
351
+ end
352
+ end
353
+
354
+ test "errors on invalid index" , % { stmt: stmt } do
355
+ assert_raise Exqlite.Error , "column index out of range" , fn ->
356
+ Sqlite3 . bind_blob ( stmt , _out_of_range = 2 , "hello" )
357
+ end
358
+ end
359
+
360
+ test "errors on invalid blob argument" , % { stmt: stmt } do
361
+ assert_raise ArgumentError , "argument error: 1" , fn ->
362
+ Sqlite3 . bind_blob ( stmt , 1 , _not_text = 1 )
363
+ end
364
+ end
365
+ end
366
+
300
367
describe ".columns/2" do
301
368
test "returns the column definitions" do
302
369
{ :ok , conn } = Sqlite3 . open ( ":memory:" )
0 commit comments