bug-apl
[Top][All Lists]
Advanced

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

Re: [Bug-apl] SQL support


From: Juergen Sauermann
Subject: Re: [Bug-apl] SQL support
Date: Sat, 12 Apr 2014 16:09:36 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130330 Thunderbird/17.0.5

Hi Elias,

Wow, looks cool!

/// Jürgen


On 04/11/2014 10:48 AM, Elias Mårtenson wrote:
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]