Queries to a customize table using ODBC and sqlite3

Hi! I’m using PJSIP with Asterisk16 and I would like to read and write to a customize table using ODBC and sqlite. This is my configuration:

/etc/odbc.ini
[asterisk]
Description=SQLite3 database
Driver=SQLite3
Database=/var/lib/asterisk/sqlite3dir/sqlite3.db
Timeout=2000

/etc/odbcinst.ini
[SQLite3]
Description=SQLite3 ODBC Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libsqlite3odbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libsqlite3odbc.so
Threading=2

/etc/asterisk/modules.conf
preload => res_odbc.so
preload => res_config_odbc.so
noload => app_directory_odbc.so
;noload => res_config_odbc.so

[SQL]
readsql=${ARG1}
dsn=asterisk

Where should I create my customize table? inside “/var/lib/asterisk/sqlite3dir/sqlite3.db”?

The idea is to execute from extensions.conf
exten => 123,1,Set(Name=${ ODBC_SQL (SELECT value FROM my_table WHERE id=‘key’)})

But I get the following error:
res_odbc.c:538 ast_odbc_print_errors: SQL Prepare returned an error: HY000: [SQLite]no such table: my_table (1)

Thanks!

I can read data from everywhere, but can not write data or create objects, because the database is locked by Asterisk. To write data or pass DDL statements use Asterisk dialplan functions.

From within the dialplan I think it is best to use dialplan DB functions. For example, FreePBX holds a lot of information in AstDB.

Hi! Thanks for your answer. I’ve used the DB functions, but if I well understood, those are for the internal asterisk database. What I want is to create a new table in sqlite and read and write it. Is it possible to create new tables? I created a sqlite database and stored it “/var/lib/asterisk/sqlite3dir/sqlite3.db” (the path included in /etc/odbc.ini file), but I still get errors when reading from it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.