bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-apl] SQL support


From: Elias Mårtenson
Subject: [Bug-apl] SQL support
Date: Fri, 11 Apr 2014 16:48:23 +0800

I've been working on an SQL interface, and right now I'm at the point where basic SQLite support works. Here's an example:

      ⍝ Load the native library
      '/home/emartenson/prog/apl-sqlite/lib_sqlite.so' ⎕FX 'SQL'
SQL

      ⍝ Open the SQLite database in the file /tmp/foo
      db ← SQL[1] '/tmp/foo'

      ⍝ Run an SQL statement to create a new table
      db SQL[4] 'create table foo (id int primary key, value varchar(10))'

      ⍝ Insert 10 rows of data into the table
      {db SQL[4] 'insert into foo (id,value) values (?,?)' ⍵ ('foo:',⍕⍵)}¨ ⍳10

      ⍝ Select a few rows of data from the table
      8⎕CR db SQL[3] 'select * from foo where id < 4'
┌→────────┐
↓1 ┌→────┐│
│  │foo:1││
│  └─────┘│
│2 ┌→────┐│
│  │foo:2││
│  └─────┘│
│3 ┌→────┐│
│  │foo:3││
│  └─────┘│
└∊────────┘

      ⍝ Close the database
      SQL[2] db

The code is available here: https://github.com/lokedhs/apl-sqlite

Contrary to the project name, it's written in a way so that support for other SQL databases can be easily plugged in.

Regards,
Elias

reply via email to

[Prev in Thread] Current Thread [Next in Thread]