libraryextensions/sqlite/lib/Sqlite.xtl

Sqlite.xtl -- the facade of the sqlite extension: SQLite databases for X_eTaL (rusqlite, SQLite compiled in). Import: "sq:" u_se< "Sqlite" A database is named by its path, relative to the working directory (or XETAL_SQLITE_ROOT), or ":memory:" for one call's scratch database; each call opens it and closes it. Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH). Each signature line is written out by the binding macro (lib/Ffi.xtlm).

source · imports ffi: lib/Ffi.xtlm

ˡe̲xec : Char -> Char -> Int

function · line 13

db sq:e_xec sql: run the statements; how many rows they changed.

"e_xec : text text -> int"      ᶠᶠⁱb̲ind< "sqlite/exec"
ᶠᶠⁱb̲ind< expands to
ˡe̲xec ← { a b →
  pa ← a ⎕N̲PUT "ext:sqlite/exec?text"
  pb ← b ⎕N̲PUT "ext:sqlite/exec?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:sqlite/exec"
}

ˡn̲ums : Char -> Char -> Float

function · line 15

db sq:n_ums sql: the result as a Float matrix, rows by columns (NULL is NaN).

"n_ums : text text -> floats"   ᶠᶠⁱb̲ind< "sqlite/nums"
ᶠᶠⁱb̲ind< expands to
ˡn̲ums ← { a b →
  pa ← a ⎕N̲PUT "ext:sqlite/nums?text"
  pb ← b ⎕N̲PUT "ext:sqlite/nums?text"
  v ← n̲umbers ⎕N̲GET "ext:sqlite/nums"
  (f̲loor n̲umbers ⎕N̲GET "ext:sqlite/nums?shape") r̲eshape v
}

ˡt̲exts : Char -> Char -> Char

function · line 18

db sq:t_exts sql: every cell as text, a Char matrix with one row per cell (the first row's cells, then the second's; padded with spaces).

"t_exts : text text -> chars"   ᶠᶠⁱb̲ind< "sqlite/texts"
ᶠᶠⁱb̲ind< expands to
ˡt̲exts ← { a b →
  pa ← a ⎕N̲PUT "ext:sqlite/texts?text"
  pb ← b ⎕N̲PUT "ext:sqlite/texts?text"
  v ← ⎕N̲GET "ext:sqlite/texts"
  (f̲loor n̲umbers ⎕N̲GET "ext:sqlite/texts?shape") r̲eshape v
}

ˡc̲ols : Char -> Char -> Char

function · line 20

db sq:c_ols sql: the query's column names, one per row.

"c_ols : text text -> chars"    ᶠᶠⁱb̲ind< "sqlite/cols"
ᶠᶠⁱb̲ind< expands to
ˡc̲ols ← { a b →
  pa ← a ⎕N̲PUT "ext:sqlite/cols?text"
  pb ← b ⎕N̲PUT "ext:sqlite/cols?text"
  v ← ⎕N̲GET "ext:sqlite/cols"
  (f̲loor n̲umbers ⎕N̲GET "ext:sqlite/cols?shape") r̲eshape v
}

ˡq̲uote : Char -> Char

function · line 23

sq:q_uote t: the text as an SQL literal ('O''Brien'), to put a value into a statement as data, never as SQL.

"q_uote : text -> text"         ᶠᶠⁱb̲ind< "sqlite/quote"
ᶠᶠⁱb̲ind< expands to
ˡq̲uote ← { a →
  pa ← a ⎕N̲PUT "ext:sqlite/quote?text"
  ⎕N̲GET "ext:sqlite/quote"
}

ˡi̲mport : Char -> Char -> Int

function · line 28

db sq:i_mport "path.csv" (or "table=path.csv"): a CSV file into a new table named after the file; the header names the columns, their types (INTEGER, REAL, TEXT) come from the data; empty fields are NULL. How many rows it imported.

"i_mport : text text -> int"    ᶠᶠⁱb̲ind< "sqlite/import"
ᶠᶠⁱb̲ind< expands to
ˡi̲mport ← { a b →
  pa ← a ⎕N̲PUT "ext:sqlite/import?text"
  pb ← b ⎕N̲PUT "ext:sqlite/import?text"
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:sqlite/import"
}
Used in: ˡr̲eport, n

ˡpackage : Char

value · line 31

The native package behind these functions.

ˡpackage ← "sqlite"