Home /Modules/sleela-sql/README.md

README.md

lib/sleela-sql/examples/README.md · 51 line(s) · markdown

<img align="right" src="https://github.com/mearvk/SLeeLa/blob/master/images/debian/debian-logo.png" width="75" height="75" alt="SLeeLa">

SLeeLa SQL examples

These examples use the local CSV-backed sleela-sql command-line engine. Run commands from the repository root or adjust paths as needed.

Build

make -C lib/sleela-sql
make -C lib/sleela-sql test

Run examples

Each non-comment line is one statement. The engine creates the database directory if it does not exist; the parent directory must already exist.

mkdir -p /tmp/sleela-sql-demo
lib/sleela-sql/build/sleela-sql /tmp/sleela-sql-demo < lib/sleela-sql/examples/01-create-table.sql
lib/sleela-sql/build/sleela-sql /tmp/sleela-sql-demo < lib/sleela-sql/examples/02-insert.sql
lib/sleela-sql/build/sleela-sql /tmp/sleela-sql-demo < lib/sleela-sql/examples/03-select.sql
lib/sleela-sql/build/sleela-sql /tmp/sleela-sql-demo < lib/sleela-sql/examples/04-update.sql
lib/sleela-sql/build/sleela-sql /tmp/sleela-sql-demo < lib/sleela-sql/examples/05-delete.sql

Use a fresh database directory if you want to replay the create-table example from the beginning.

Example catalog

FilePurpose
01-create-table.sqlCreate a table, including idempotent creation
02-insert.sqlInsert rows, including values containing commas
03-select.sqlSelect columns, filter rows, and count matches
04-update.sqlChange one or more values in matching rows
05-delete.sqlDelete matching rows and inspect the remaining count
06-list-and-drop.sqlList tables and drop a table
07-fluent.ssqlExamples using the fluent SLeeLaSQL dialect
08-prepared-statements.cReuse a prepared statement with bound parameters
09-alter-table-add-column.sqlAdd a column with an empty default for existing rows
09-alter-table-proposal.sqlHistorical design note; the feature is now implemented
10-alter-table-default.sqlAdd a column and populate existing rows with a default value
11-alter-table-errors.sqlDemonstrate duplicate-column rejection (second statement expects an error)
slsql/Dedicated SLSQL language walkthrough with runnable .ssql examples, prepared statements, and SQL equivalents

ALTER TABLE / ADD COLUMN

The native engine supports classic-SQL ALTER TABLE table ADD [COLUMN] column [DEFAULT value]. Existing rows receive the supplied default or an empty string. The operation writes a temporary CSV and replaces the original using the platform-specific replacement routine; it rejects duplicate columns and tables already at the 64-column limit. Back up important CSV data before schema migrations. The fluent SLeeLaSQL dialect does not yet expose ALTER TABLE, UPDATE, or DELETE.

These are examples of the implemented SQL subset, not a claim of full SQL-standard compatibility.