|
@@ -81,29 +81,29 @@ Chapter 1. Admin Guide
|
|
|
|
|
|
1. Overview
|
|
|
|
|
|
- The module adds support for raw SQL queries in the configuration file.
|
|
|
+ The SQLOPS module adds support for raw SQL queries in the configuration
|
|
|
+ file.
|
|
|
|
|
|
Among the features:
|
|
|
- * Multiple DB connections - the module can connect to many databases
|
|
|
- on different servers using different DB driver modules at the same
|
|
|
- time.
|
|
|
- * many DB results - the module can store many results of different
|
|
|
+ * Multiple database connections - the sqlops module can connect to
|
|
|
+ many databases on different servers using different DB driver
|
|
|
+ modules at the same time.
|
|
|
+ * Many query results - the module can store many results of different
|
|
|
SQL queries in separate structures at the same time. Thus it is
|
|
|
- possible to work in parallel with several DB results.
|
|
|
- * access via pseudo-variables - the content of the SQL query result
|
|
|
+ possible to work in parallel with several queries and results.
|
|
|
+ * Access via pseudo-variables - the content of the SQL query result
|
|
|
is accessible via pseudo-variables. Please note that only integer
|
|
|
and string variables are supported at the moment because of the
|
|
|
internal usage of "AVPs" to hold the values. So it is not possible
|
|
|
for example to return floating point or big integer values this
|
|
|
way.
|
|
|
- * array indexes - fast access to result values via array position:
|
|
|
+ * Array indexes - fast access to result values via array position:
|
|
|
[row,column].
|
|
|
- * persistence in process space - a result can be used many times in
|
|
|
+ * Persistence in process space - a result can be used many times in
|
|
|
the same worker process. Query once, use many times.
|
|
|
- * alternatively, results can be stored in xavps - columns are
|
|
|
- accessed by their names, rows by xavp index. Xavp's are available
|
|
|
- during the transactions lifetime and don't need to be destroyed
|
|
|
- manually.
|
|
|
+ * Results can be stored in xavps - columns are accessed by their
|
|
|
+ names, rows by xavp index. Xavp's are available during the
|
|
|
+ transactions lifetime and don't need to be destroyed manually.
|
|
|
|
|
|
2. Dependencies
|
|
|
|
|
@@ -134,27 +134,27 @@ Chapter 1. Admin Guide
|
|
|
|
|
|
This parameter may be set multiple times to get many DB connections in
|
|
|
the same configuration file.
|
|
|
- * connection_name - string specifying the name of a DB connection.
|
|
|
- This string is used by the "sql_query()" function to refer to the
|
|
|
- DB connection.
|
|
|
- * database_url - Standardized database URL used to connect to
|
|
|
- database.
|
|
|
+ * connection_name - string specifying the name of a database
|
|
|
+ connection. This string is used by the "sql_query()" function to
|
|
|
+ refer to the DB connection.
|
|
|
+ * database_url - Standardized Kamailio database URL used to connect
|
|
|
+ to database.
|
|
|
|
|
|
Default value is NULL.
|
|
|
|
|
|
Example 1.1. Set sqlcon parameter
|
|
|
...
|
|
|
-modparam("sqlops","sqlcon","cb=>mysql://openser:[email protected]/testdb")
|
|
|
+modparam("sqlops","sqlcon","cb=>mysql://kamailio:[email protected]/testdb")
|
|
|
modparam("sqlops","sqlcon","ca=>dbdriver://username:password@dbhost/dbname")
|
|
|
...
|
|
|
|
|
|
3.2. sqlres (str)
|
|
|
|
|
|
- The definition of a DB result ID. The value of the parameter can be any
|
|
|
- string. Results IDs are also added at fixup time when sql_query()
|
|
|
- parameters are parsed, there is no need to decalare them via module
|
|
|
- parameter unless you want to use them from within other modules and be
|
|
|
- available in all application processes.
|
|
|
+ The definition of a database result ID. The value of the parameter can
|
|
|
+ be any string. Results IDs are also added at fixup time when
|
|
|
+ sql_query() parameters are parsed, so there is no need to decalare them
|
|
|
+ via module parameter unless you want to use them from within other
|
|
|
+ modules and be available in all application processes.
|
|
|
|
|
|
Default value is NULL.
|
|
|
|
|
@@ -170,10 +170,10 @@ modparam("sqlops", "sqlres", "ra")
|
|
|
4.3. sql_pvquery(connection, query, result)
|
|
|
4.4. sql_result_free(result)
|
|
|
|
|
|
-4.1. sql_query(connection, query[, result])
|
|
|
+4.1. sql_query(connection, query[, result])
|
|
|
|
|
|
Make an SQL query using 'connection' and store data in 'result'.
|
|
|
- * connection - the name of the connection to be used for query
|
|
|
+ * connection - the name of the connection to be used for the query
|
|
|
(defined via the "sqlcon" parameter).
|
|
|
* query - SQL query string or pseudo-variables containing SQL query.
|
|
|
* result - string name to identify the result. Will be used by
|
|
@@ -193,10 +193,10 @@ xlog("number of rows in table domain: $dbr(ra=>rows)\n");
|
|
|
sql_result_free("ra");
|
|
|
...
|
|
|
|
|
|
-4.2. sql_xquery(connection, query, result)
|
|
|
+4.2. sql_xquery(connection, query, result)
|
|
|
|
|
|
Make an SQL query using 'connection' and store data in 'result' xavp.
|
|
|
- * connection - the name of the connection to be used for query
|
|
|
+ * connection - the name of the connection to be used for the query
|
|
|
(defined via the "sqlcon" parameter).
|
|
|
* query - SQL query string or pseudo-variables containing SQL query.
|
|
|
* result - string name to identify the result xavp. Each row will be
|
|
@@ -212,10 +212,10 @@ sql_xquery("ca", "select * from domain", "ra");
|
|
|
xlog("first domain: $xavp(ra=>domain) with id: $xavp(ra=>domain_id)\n");
|
|
|
...
|
|
|
|
|
|
-4.3. sql_pvquery(connection, query, result)
|
|
|
+4.3. sql_pvquery(connection, query, result)
|
|
|
|
|
|
- Make an SQL query using 'connection' and store data in arbitrary PV's
|
|
|
- specified by 'result' parameter.
|
|
|
+ Make an SQL query using 'connection' and store data in arbitrary pseudo
|
|
|
+ variables specified by 'result' parameter.
|
|
|
* connection - the name of the connection to be used for query
|
|
|
(defined via the "sqlcon" parameter).
|
|
|
* query - SQL query string or pseudo-variables containing SQL query.
|
|
@@ -240,11 +240,11 @@ sql_xquery("ca", "select * from domain", "ra");
|
|
|
...
|
|
|
modparam("sqlops","sqlcon","ca=>dbdriver://username:password@dbhost/dbname")
|
|
|
...
|
|
|
-sql_xquery("ca", "select 'col1', 2, NULL, 'sip:[email protected]'",
|
|
|
+sql_pvquery("ca", "select 'col1', 2, NULL, 'sip:[email protected]'",
|
|
|
"$var(a), $avp(col2), $xavp(item[0]=>s), $ru");
|
|
|
...
|
|
|
|
|
|
-4.4. sql_result_free(result)
|
|
|
+4.4. sql_result_free(result)
|
|
|
|
|
|
Free data in SQL 'result'.
|
|
|
|
|
@@ -334,10 +334,10 @@ if (sql_xquery("ca", "select * from domain", "ra") == 1)
|
|
|
5.2. $sqlrows(con)
|
|
|
|
|
|
Number of affected rows of the previous query on the specified
|
|
|
- connection. Its primary use is to get the number of rows affected by
|
|
|
+ connection. It's primary use is to get the number of rows affected by
|
|
|
UPDATE, INSERT and DELETE queries.
|
|
|
|
|
|
- "con" must be the name identifying an SQL connection.
|
|
|
+ "con" must be the name identifying a DB connection.
|
|
|
|
|
|
Example 1.8. $sqlrows(con) usage
|
|
|
...
|