#!/bin/sh

# create an (empty) SQLite3 database file for testing

echo "Creating an SQLite3 database for testing"
sqlite3 test_db.sqlite << _EOF_
CREATE TABLE IF NOT EXISTS table1 (col1, col2);
.exit
_EOF_
echo ""

# run Python and try to enable load_extensions()

echo "-"
echo "Run Python, import sqlite3 module, enable loading of extensions"
python << _EOF_
import sqlite3
# print some information about SQLite
print 'SQLite 3 Python Module Info:'
print 'sqlite3.version ............', sqlite3.version
print 'sqlite3.version_info .......', sqlite3.version_info
print 'sqlite3.sqlite_version .....', sqlite3.sqlite_version
# create a connection object
db_conn = sqlite3.connect('test_db.sqlite')
# create a cursor object
cur = db_conn.cursor()
# display compilation state of loading extensions
cur.execute("SELECT sqlite_compileoption_used('ENABLE_LOAD_EXTENSION');")
print 'ENABLE_LOAD_EXTENSION compile option: ', cur.fetchone()
# try to enable loading of extensions
print 'Attempting to enable load_extensions (should work...)'
db_conn.enable_load_extension(True)
# thats all folks...
exit()
_EOF_
echo ""

# Demo of loading extensions in sqlite3 (has been enabled there for sometime)

echo "-"
echo "Demo of loading extensions in sqlite3 application (should be NO errors)"
sqlite3 << _EOF_
.explain ON
.load '/usr/lib/libspatialite.so.3'
.exit
_EOF_


