JDB/ClientServer

From J Wiki
< JDB
Jump to navigation Jump to search
JDB: Layout Columns | Queries Σ | API: Structural Records | Client/Server | Implementation | Examples

A basic client/server is in scripts jdbclient.ijs and jdbserver.ijs.

Server

Verb jdbinit initializes the server. The argument is a pair: database folder;port. Typically, this is run in a console session.

For example, load J console, then:

load 'data/jdb'
load 'data/jdb/jdbserver'
buildsandp_jdb_ 'c:\mydata'    NB. build demo sandp database
jdbinit 'c:\mydata';1200

Client

Script jdbclient.ijs has a corresponding client. After initializing the connection, all calls are made with verb jdb. The argument is a triple: method;database locale;parameters, where locale is empty for database methods. For example:

   load 'data/jdb/jdbclient'
   a=: 1200 conew 'jdbclient'
   d=: jdb__a 'Open';'';'sandp'
   jdb__a 'Reads';d;'from sp where qty>=300'
+---+---+---+
|sid|pid|qty|
+---+---+---+
|S1 |P1 |300|
|S1 |P3 |400|
|S2 |P1 |300|
|S2 |P2 |400|
|S4 |P4 |300|
|S4 |P5 |400|
+---+---+---+