Valentina ADK API FAQs
This page collects FAQs about Valentina ADK API in general, i.e. valid for any Valentina ADK. You may want also check FAQ pages specific to particular ADK.
SQL Binding Methods
Q: Why I should prefer to use SQL binding? It requires more code.
SQL binding has two major advantages:
1) It is more effective faster. Especially when you do a loop with N INSERTs. Because parser is called only once.
2) It allows avoiding of SQL injection attacks.
Q: What should I prefer to use db.SqlExecute() or VSqlStatement.SqlExecute()?
You should prefer to use VSqlStatement in hot loops and you can use SqlExecute()/SqlSelect() in single commands.
Let's compare two examples:
dim query as String = "INSERT INTO T1 VALUES(?,?,?)"
for i = 1 to 100000
db.SqlExecute( query, Array(i,i+1,i+2) )
next
dim query as String = "INSERT INTO T1 VALUES(?,?,?)"
dim stmt as VSqlStatement = db.Prepare( query )
for i = 1 to 100000
stmt.bind_uint32( 0, i )
stmt.bind_uint32( 1, i+1 )
stmt.bind_uint32( 2, i+2 )
stmt.SqlExecute()
next
Both examples use SQL binding. But the first use implicit mechanism of caching of queries with binding in Valentina DB. This mechanism caches all queries that have SQL binding in the state of trees after SQL parser. This makes things faster comparing to the case without SQL binding. When ValentinaDB gets a query, it, first of all, search its hash (i.e. byte to byte) between all cached queries.
The second example is even faster because of no need to search a query between cached queries. You have a direct pointer to it thanks to VSqlStatement object.
Q: Why bind_vvv() methods have index parameter?
Why do we need to put efforts to carefully specify index parameter in this methods? Why not just as kind append()?
We did follow most other products in this regard.
Most probably this can be more flexible in some cases. For example, you do a loop with INSERTs, but you want to change only one field, while others are the same for all records. So you can change only that field.
At the same time, we think it is possible really to have a similar group of methods append_bool(), append_string(), etc.