DIAdem Help

Command: SQLiteQuery

  • Updated2024-09-12
  • 3 minute(s) read

Display all  Hide all

Command: SQLiteQuery

Executes an SQLite database query.

ReturnValue = SQLiteQuery(SQLiteQueryString, SQLiteOutputHeader)

Input Parameters

SQLiteQueryString Specifies the SQL statement to be executed.
SQLiteOutputHeader Specifies whether a row with column headers should be displayed.

Return Parameters

ReturnValue Receives the result of an SQLite database query in form of an array.

Example

The following example opens the SQLite database "Cities_1000_V4.4.sqlite" and loads the database extension "mod_spatialite4.dll" with the entry point  "sqlite3_modspatialite_init". The example then performs various searches in the database and displays the results in the logfile.

VBScriptPython

 

Call SQLiteOpen(DataReadPath & "Cities_1000_V4.4.sqlite")
Call SQLiteAddExtension("mod_spatialite4.dll", "sqlite3_modspatialite_init")
Call SQLQuery("SELECT Name FROM cities1000 LIMIT 10;", True)
Call SQLQuery("SELECT Name FROM cities1000 ORDER BY Distance(geom_wsg84, MakePoint(cast(12.4876180 AS DOUBLE), cast(41.9029000 AS DOUBLE), 4326)) LIMIT 5;", True)
Call SQLQuery("SELECT * FROM knn WHERE f_table_name = 'cities1000' AND ref_geometry = MakePoint(cast(12.4876180 AS DOUBLE), cast(41.9029000 AS DOUBLE)) LIMIT 5;", True)
Call SQLQuery("SELECT Name FROM cities1000 LIMIT 10;", False)
Call SQLQuery("SELECT Name FROM cities1000 ORDER BY Distance(geom_wsg84, MakePoint(cast(12.4876180 AS DOUBLE), cast(41.9029000 AS DOUBLE), 4326)) LIMIT 5;", False)
Call SQLQuery("SELECT * FROM knn WHERE f_table_name = 'cities1000' AND ref_geometry = MakePoint(cast(12.4876180 AS DOUBLE), cast(41.9029000 AS DOUBLE)) LIMIT 5;", False)
Call SQLiteClose()

Sub SQLQuery(sQuery, bOutputHeader)
  Dim aResult, sText, iRow, iColumn
  Call LogFileWrite("sQuery: " & sQuery)
  Call LogFileWrite("-----------------------------")
  Result = SQLiteQuery(sQuery, bOutputHeader)
  If IsArray(aResult) Then
    For iRow = lBound(aResult,1) To uBound(aResult,1)
      sText = ""
      For iColumn = lBound(aResult, 2) To uBound(aResult,2)
        sText = sText & Left(aResult(iRow, iColumn) & Space(25), 20)
      Next
      LogFileWrite(sText)
    Next
  End If
  Call LogfileWrite(" ")
  Call LogfileWrite(" ")
End Sub

Related Topics

Command: SQLiteAddExtension | Command: SQLiteClose | Command: SQLiteOpen