1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
START_MARKER 
 
test_any([[ 
  Sql.Sql sql = Sql.Sql("null://"); 
  return sql->query("INSERT INTO foo (foo, bar) VALUES (%s, %s) WHERE bar = %d", 
                    0, "blah", 0)[0]->query; 
]], "INSERT INTO foo (foo, bar) VALUES (%s, %s) WHERE bar = %d") 
 
test_any([[ 
  Sql.Sql sql = Sql.Sql("null://"); 
  return sql->query("INSERT INTO foo (foo, bar) VALUES (%s, %s) WHERE bar = %d", 
                    0, "blah", 0)[0]->bindings_query; 
]], "INSERT INTO foo (foo, bar) VALUES (NULL, :arg0) WHERE bar = 0") 
 
test_any([[ 
  Sql.Sql sql = Sql.Sql("null://"); 
  return sql->query("INSERT INTO foo (foo, bar) VALUES (%s, %s) WHERE bar = %d", 
                    0, "blah", 0)[0]->formatted_query; 
]], "INSERT INTO foo (foo, bar) VALUES (NULL, 'quote(\"blah\")') WHERE bar = 0") 
 
test_do([[ 
  catch { 
    add_constant( "db", Sql.Sql("mysql://localhost") ); 
  }; 
]]) 
 
ifefun(db,[[ 
  test_equal( db->query("select 1"), ({ ([ "1":"1" ]) }) ) 
  test_eq( db->big_query("select 1")->num_rows(), 1 ) 
  test_eq( db->big_query("select 1,2")->num_fields(), 2 ) 
  test_equal( db->big_query("select 1")->fetch_fields()->name, ({ "1" }) ) 
  test_eq( 1, [[#pragma no_deprecation_warnings 
    objectp(db->big_query("select 1")->master_res) 
  ]]) 
  test_eq( db->big_query("select 1")->index, 0 ) 
  test_any([[ 
    object q=db->big_query("show status"); 
    q->seek(2); 
    return q->index; 
  ]], 2 ) 
  test_equal( db->big_query("select 1,2")->fetch_row(), ({ "1", "2" }) ) 
  test_do([[ 
    object q=db->big_query("show status"); 
    q->seek( q->num_rows()+7 ); 
  ]]) 
  test_do( add_constant("db") ) 
]]) 
 
test_eq( Sql.sql_array_result(({(["1":"1"])}))->num_rows(), 1 ) 
test_eq( Sql.sql_array_result(({(["a":"1","b":"2"])}))->num_fields(), 2 ) 
test_equal( Sql.sql_array_result(({(["a":"1","b":"2"])}))->fetch_fields(), 
            ({ ([ "name":"a" ]), ([ "name":"b" ]) }) ) 
test_true( arrayp(Sql.sql_array_result(({(["1":"1"])}))->master_res) ) 
test_eq( Sql.sql_array_result(({(["1":"1"])}))->index, 0 ) 
test_any([[ 
  object q=Sql.sql_array_result(({(["a":"1"]),(["a":"2"])})); 
  q->seek(1); 
  return q->index; 
]], 1 ) 
test_equal( Sql.sql_array_result(({(["a":"1"])}))->fetch_row(), ({ "1" }) ) 
test_do([[ 
  object q=Sql.sql_array_result(({(["a":"1"]),(["a":"2"])})); 
  q->seek(77); 
]]) 
 
END_MARKER