Table creation/Postal addresses: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: syntax coloured, marked p2js incompatible)
m (syntax highlighting fixup automation)
Line 15: Line 15:


<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - needed formatted transput}} -->
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - needed formatted transput}} -->
<lang algol68>MODE ADDRESS = STRUCT(
<syntaxhighlight lang="algol68">MODE ADDRESS = STRUCT(
INT page,
INT page,
FLEX[50]CHAR street,
FLEX[50]CHAR street,
Line 60: Line 60:
# set(address table, page OF john brown,1,1); - standard set page not available in a68g #
# set(address table, page OF john brown,1,1); - standard set page not available in a68g #
put bin(address table, john brown);
put bin(address table, john brown);
close(address table)</lang>
close(address table)</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 71: Line 71:


=={{header|Apache Derby}}==
=={{header|Apache Derby}}==
<lang SQL>create table Address (
<syntaxhighlight lang="sql">create table Address (
addrID integer primary key generated by default as identity,
addrID integer primary key generated by default as identity,
addrStreet varchar(50) not null,
addrStreet varchar(50) not null,
Line 78: Line 78:
addrZip char(10) not null
addrZip char(10) not null
);
);
</syntaxhighlight>
</lang>
'''Interactive session:
'''Interactive session:
<pre style="height: 30em; overflow: scroll">
<pre style="height: 30em; overflow: scroll">
Line 129: Line 129:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>db: open.sqlite "addresses.db"
<syntaxhighlight lang="rebol">db: open.sqlite "addresses.db"


query db {!sql
query db {!sql
Line 141: Line 141:
}
}


close db</lang>
close db</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
Line 149: Line 149:
This version uses the AWK pipe, 'getline' function, and the sqlite3 command line program.
This version uses the AWK pipe, 'getline' function, and the sqlite3 command line program.


<lang awk>#!/bin/sh -f
<syntaxhighlight lang="awk">#!/bin/sh -f
awk '
awk '
BEGIN {
BEGIN {
Line 181: Line 181:
}
}


'</lang>
'</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
{{libheader|SQLite}}
{{libheader|SQLite}}
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <sqlite3.h>
Line 216: Line 216:
}
}
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(require '[clojure.java.jdbc :as sql])
<syntaxhighlight lang="clojure">(require '[clojure.java.jdbc :as sql])
; Using h2database for this simple example.
; Using h2database for this simple example.
(def db {:classname "org.h2.Driver"
(def db {:classname "org.h2.Driver"
Line 232: Line 232:
[:state "varchar"]
[:state "varchar"]
[:zip "varchar"]))
[:zip "varchar"]))
</syntaxhighlight>
</lang>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang scheme>
<syntaxhighlight lang="scheme">
(lib 'struct)
(lib 'struct)
(lib 'sql)
(lib 'sql)
Line 252: Line 252:
[0] 15 Gallubert 29 rue de l'Ermitage Paris Seine 75020
[0] 15 Gallubert 29 rue de l'Ermitage Paris Seine 75020
[1] 16 Brougnard 666 rue des Cascades Paris Seine 75042
[1] 16 Brougnard 666 rue des Cascades Paris Seine 75042
</syntaxhighlight>
</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==
Erlang has built in databases. This is the the one with most features: Mnesia. There are database connectors to other databases, too.
Erlang has built in databases. This is the the one with most features: Mnesia. There are database connectors to other databases, too.
<syntaxhighlight lang="erlang">
<lang Erlang>
-module( table_creation ).
-module( table_creation ).


Line 266: Line 266:
mnesia:start(),
mnesia:start(),
mnesia:create_table( address, [{attributes, record_info(fields, address)}] ).
mnesia:create_table( address, [{attributes, record_info(fields, address)}] ).
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 275: Line 275:
=={{header|FunL}}==
=={{header|FunL}}==
FunL has built-in support for H2 and comes bundled with the H2 database engine.
FunL has built-in support for H2 and comes bundled with the H2 database engine.
<lang funl>import db.*
<syntaxhighlight lang="funl">import db.*
import util.*
import util.*


Line 311: Line 311:
print( TextTable.apply(result) )
print( TextTable.apply(result) )


conn.close()</lang>
conn.close()</syntaxhighlight>


{{out}}
{{out}}
Line 325: Line 325:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 371: Line 371:
fmt.Println(field, storage)
fmt.Println(field, storage)
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 386: Line 386:
{{libheader|sqlite-simple}}
{{libheader|sqlite-simple}}


<lang haskell>{-# LANGUAGE OverloadedStrings #-}
<syntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}


import Database.SQLite.Simple
import Database.SQLite.Simple
Line 400: Line 400:
\addrZIP TEXT NOT NULL \
\addrZIP TEXT NOT NULL \
\)"
\)"
close db</lang>
close db</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
J is a programming language, not a database, but it ships with a database built in the programming language called [[j:JDB|JDB]]. Using that, assuming <tt>hd</tt> is your database, then:
J is a programming language, not a database, but it ships with a database built in the programming language called [[j:JDB|JDB]]. Using that, assuming <tt>hd</tt> is your database, then:


<lang j> Create__hd 'Address';noun define
<syntaxhighlight lang="j"> Create__hd 'Address';noun define
addrID autoid;
addrID autoid;
addrStreet varchar
addrStreet varchar
Line 411: Line 411:
addrState char
addrState char
addrZip char
addrZip char
)</lang>
)</syntaxhighlight>


Of course J can connect external databases too, using e.g. [[j:Studio/ODBC%20Basics|ODBC]]. See the [[j:DB|list of J database topics]].
Of course J can connect external databases too, using e.g. [[j:Studio/ODBC%20Basics|ODBC]]. See the [[j:DB|list of J database topics]].
Line 418: Line 418:
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>using SQLite
<syntaxhighlight lang="julia">using SQLite


db = SQLite.DB()
db = SQLite.DB()
Line 428: Line 428:
addrState TEXT NOT NULL,
addrState TEXT NOT NULL,
addrZIP TEXT NOT NULL)
addrZIP TEXT NOT NULL)
""")</lang>
""")</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Rather than use an external database, we use the built-in RandomAccessFile class for his task. The data used is the same as for the REXX entry.
Rather than use an external database, we use the built-in RandomAccessFile class for his task. The data used is the same as for the REXX entry.
<lang scala>// Version 1.2.41
<syntaxhighlight lang="scala">// Version 1.2.41


import java.io.File
import java.io.File
Line 520: Line 520:
println(Address.readRecord(file, i.toLong()))
println(Address.readRecord(file, i.toLong()))
}
}
}</lang>
}</syntaxhighlight>


{{output}}
{{output}}
Line 542: Line 542:
Lasso has excellent support for connecting to and handling databases.
Lasso has excellent support for connecting to and handling databases.


<lang Lasso>// connect to a Mysql database
<syntaxhighlight lang="lasso">// connect to a Mysql database
inline(-database = 'rosettatest', -sql = "CREATE TABLE `address` (
inline(-database = 'rosettatest', -sql = "CREATE TABLE `address` (
`id` int(11) NOT NULL auto_increment,
`id` int(11) NOT NULL auto_increment,
Line 553: Line 553:
") => {^
") => {^
error_msg
error_msg
^}</lang>
^}</syntaxhighlight>
Output:
Output:
<pre>No error</pre>
<pre>No error</pre>
Line 559: Line 559:
=={{header|Lua}}==
=={{header|Lua}}==
Using LJSQLite3 - compatible with LuaJIT and supplied in the ULua distribution.
Using LJSQLite3 - compatible with LuaJIT and supplied in the ULua distribution.
<lang Lua>-- Import module
<syntaxhighlight lang="lua">-- Import module
local sql = require("ljsqlite3")
local sql = require("ljsqlite3")


Line 576: Line 576:


-- Explicitly close connection
-- Explicitly close connection
conn:close()</lang>
conn:close()</syntaxhighlight>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>TableCreation="CREATE TABLE address (
<syntaxhighlight lang="mathematica">TableCreation="CREATE TABLE address (
addrID INTEGER PRIMARY KEY AUTOINCREMENT,
addrID INTEGER PRIMARY KEY AUTOINCREMENT,
addrStreet TEXT NOT NULL, addrCity TEXT NOT NULL,
addrStreet TEXT NOT NULL, addrCity TEXT NOT NULL,
Line 585: Line 585:
Needs["DatabaseLink`"]
Needs["DatabaseLink`"]
conn=OpenSQLConnection[ JDBC[ "mysql","databases:1234/conn_test"], "Username" -> "test"]
conn=OpenSQLConnection[ JDBC[ "mysql","databases:1234/conn_test"], "Username" -> "test"]
SQLExecute[ conn, TableCreation]</lang>
SQLExecute[ conn, TableCreation]</syntaxhighlight>


=={{header|MySQL}}==
=={{header|MySQL}}==
<lang mysql>CREATE TABLE `Address` (
<syntaxhighlight lang="mysql">CREATE TABLE `Address` (
`addrID` int(11) NOT NULL auto_increment,
`addrID` int(11) NOT NULL auto_increment,
`addrStreet` varchar(50) NOT NULL default '',
`addrStreet` varchar(50) NOT NULL default '',
Line 595: Line 595:
`addrZIP` char(10) NOT NULL default '',
`addrZIP` char(10) NOT NULL default '',
PRIMARY KEY (`addrID`)
PRIMARY KEY (`addrID`)
);</lang>
);</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
Line 602: Line 602:
{{libheader|Apache Derby}}
{{libheader|Apache Derby}}
This sample creates a table in an embedded Apache Derby database.
This sample creates a table in an embedded Apache Derby database.
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
options replace format comments java crossref symbols binary


Line 662: Line 662:
createTable()
createTable()
return
return
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import db_sqlite as db
<syntaxhighlight lang="nim">import db_sqlite as db
#import db_mysql as db
#import db_mysql as db
#import db_postgres as db
#import db_postgres as db
Line 682: Line 682:
addrState TEXT NOT NULL,
addrState TEXT NOT NULL,
addrZIP TEXT NOT NULL)"""
addrZIP TEXT NOT NULL)"""
c.close()</lang>
c.close()</syntaxhighlight>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<lang oorexx>/* REXX ***************************************************************
<syntaxhighlight lang="oorexx">/* REXX ***************************************************************
* 17.05.2013 Walter Pachl translated from REXX version 2
* 17.05.2013 Walter Pachl translated from REXX version 2
* nice try? improvements are welcome as I am rather unexperienced
* nice try? improvements are welcome as I am rather unexperienced
Line 725: Line 725:
Say ' state -->' self~state
Say ' state -->' self~state
Say ' zip -->' self~zip
Say ' zip -->' self~zip
Say copies('-',40)</lang>
Say copies('-',40)</syntaxhighlight>
Output is as for REXX version 2
Output is as for REXX version 2


=={{header|Oracle}}==
=={{header|Oracle}}==
<lang sql>CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
<syntaxhighlight lang="sql">CREATE SEQUENCE seq_address_pk START BY 100 INCREMENT BY 1
/
/
CREATE TABLE address (
CREATE TABLE address (
Line 739: Line 739:
CONSTRAINT address_pk1 PRIMARY KEY ( addrID )
CONSTRAINT address_pk1 PRIMARY KEY ( addrID )
)
)
/</lang>
/</syntaxhighlight>


=={{header|Oz}}==
=={{header|Oz}}==
Line 748: Line 748:


The SQLite version that comes with Ozsqlite does not understand "AUTOINCREMENT".
The SQLite version that comes with Ozsqlite does not understand "AUTOINCREMENT".
<lang oz>declare
<syntaxhighlight lang="oz">declare
[Sqlite] = {Module.link ['x-ozlib:/sqlite/Sqlite.ozf']}
[Sqlite] = {Module.link ['x-ozlib:/sqlite/Sqlite.ozf']}


Line 769: Line 769:
finally
finally
{Sqlite.close DB}
{Sqlite.close DB}
end</lang>
end</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use DBI;
<syntaxhighlight lang="perl">use DBI;


my $db = DBI->connect('DBI:mysql:database:server','login','password');
my $db = DBI->connect('DBI:mysql:database:server','login','password');
Line 788: Line 788:


my $exec = $db->prepare($statment);
my $exec = $db->prepare($statment);
$exec->execute;</lang>
$exec->execute;</syntaxhighlight>


This example uses mysql, but DBI supports a extensive list of database drivers. See [http://dbi.perl.org/ dbi.perl.org] for more info.
This example uses mysql, but DBI supports a extensive list of database drivers. See [http://dbi.perl.org/ dbi.perl.org] for more info.
Line 794: Line 794:
=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|SQLite}}
{{libheader|SQLite}}
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pSQLite</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pSQLite</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 813: Line 813:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"sqlite3_exec error: %d [%s]\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sqlite_last_exec_err</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"sqlite3_exec error: %d [%s]\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sqlite_last_exec_err</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHP}}+SQLite==
=={{header|PHP}}+SQLite==
{{trans|Python}}
{{trans|Python}}
not tested
not tested
<lang php><?php
<syntaxhighlight lang="php"><?php
$db = new SQLite3(':memory:');
$db = new SQLite3(':memory:');
$db->exec("
$db->exec("
Line 829: Line 829:
)
)
");
");
?></lang>
?></syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
Line 837: Line 837:


Define an "address" entity, and create the database:
Define an "address" entity, and create the database:
<lang PicoLisp>(class +Adr +Entity)
<syntaxhighlight lang="picolisp">(class +Adr +Entity)
(rel nm (+Sn +Idx +String)) # Name [Soundex index]
(rel nm (+Sn +Idx +String)) # Name [Soundex index]
(rel str (+String)) # Street
(rel str (+String)) # Street
Line 848: Line 848:
(rel jpg (+Blob)) # Photo
(rel jpg (+Blob)) # Photo


(pool "address.db") # Create database</lang>
(pool "address.db") # Create database</syntaxhighlight>
Create a first entry, and show it:
Create a first entry, and show it:
<lang PicoLisp>(show
<syntaxhighlight lang="picolisp">(show
(new! '(+Adr) # Create a record
(new! '(+Adr) # Create a record
'nm "FSF Inc."
'nm "FSF Inc."
'str "51 Franklin St"
'str "51 Franklin St"
'st "Boston, MA"
'st "Boston, MA"
'zip "02110-1301" ) )</lang>
'zip "02110-1301" ) )</syntaxhighlight>
Output:
Output:
<pre>{2} (+Adr)
<pre>{2} (+Adr)
Line 863: Line 863:
nm "FSF Inc."</pre>
nm "FSF Inc."</pre>
Interactive "select":
Interactive "select":
<lang PicoLisp>(select nm zip +Adr nm "FSF") # Select name, zip from Adr where name = FSF*</lang>
<syntaxhighlight lang="picolisp">(select nm zip +Adr nm "FSF") # Select name, zip from Adr where name = FSF*</syntaxhighlight>
Output:
Output:
<pre>"FSF Inc." "02110-1301" {2}</pre>
<pre>"FSF Inc." "02110-1301" {2}</pre>


=={{header|PostgreSQL}}==
=={{header|PostgreSQL}}==
<lang sql>CREATE SEQUENCE address_seq start 100;
<syntaxhighlight lang="sql">CREATE SEQUENCE address_seq start 100;
CREATE TABLE address (
CREATE TABLE address (
addrID int4 PRIMARY KEY DEFAULT nextval('address_seq'),
addrID int4 PRIMARY KEY DEFAULT nextval('address_seq'),
Line 875: Line 875:
state varchar(2) not null,
state varchar(2) not null,
zip varchar(20) not null
zip varchar(20) not null
);</lang>
);</syntaxhighlight>


=={{header|PowerShell}}+SQLite==
=={{header|PowerShell}}+SQLite==
{{libheader|SQLite}}
{{libheader|SQLite}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
Import-Module -Name PSSQLite
Import-Module -Name PSSQLite


Line 913: Line 913:
## View the data
## View the data
Invoke-SqliteQuery -DataSource $DataSource -Query "SELECT * FROM SSADDRESS" | FormatTable -AutoSize
Invoke-SqliteQuery -DataSource $DataSource -Query "SELECT * FROM SSADDRESS" | FormatTable -AutoSize
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 923: Line 923:
=={{header|PureBasic}}+SQLite==
=={{header|PureBasic}}+SQLite==
Easiest approach with sqlite. Further possible: PostgresQL or each other over ODBC.
Easiest approach with sqlite. Further possible: PostgresQL or each other over ODBC.
<syntaxhighlight lang="purebasic">
<lang Purebasic>
UseSQLiteDatabase()
UseSQLiteDatabase()
Procedure CheckDatabaseUpdate(Database, Query$)
Procedure CheckDatabaseUpdate(Database, Query$)
Line 946: Line 946:
EndIf
EndIf
closeconsole()
closeconsole()
</syntaxhighlight>
</lang>


=={{header|Python}}+SQLite==
=={{header|Python}}+SQLite==
{{libheader|SQLite}}
{{libheader|SQLite}}
<lang python>>>> import sqlite3
<syntaxhighlight lang="python">>>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> conn = sqlite3.connect(':memory:')
>>> conn.execute('''CREATE TABLE address (
>>> conn.execute('''CREATE TABLE address (
Line 960: Line 960:
)''')
)''')
<sqlite3.Cursor object at 0x013265C0>
<sqlite3.Cursor object at 0x013265C0>
>>> </lang>
>>> </syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 966: Line 966:
Racket supports a bunch of DBs, this is using sqlite, which is almost always available. Also included some further demonstrations beyond just the table creation:
Racket supports a bunch of DBs, this is using sqlite, which is almost always available. Also included some further demonstrations beyond just the table creation:


<syntaxhighlight lang="racket">
<lang Racket>
#lang at-exp racket
#lang at-exp racket


Line 1,017: Line 1,017:


(disconnect postal)
(disconnect postal)
</syntaxhighlight>
</lang>


Output:
Output:
Line 1,040: Line 1,040:
Like Perl DBI, Raku DBIish supports many different databases. An example using SQLite is shown here.
Like Perl DBI, Raku DBIish supports many different databases. An example using SQLite is shown here.


<lang perl6>use DBIish;
<syntaxhighlight lang="raku" line>use DBIish;


my $dbh = DBIish.connect('SQLite', :database<addresses.sqlite3>);
my $dbh = DBIish.connect('SQLite', :database<addresses.sqlite3>);
Line 1,053: Line 1,053:
addrZIP TEXT NOT NULL
addrZIP TEXT NOT NULL
)
)
STATEMENT</lang>
STATEMENT</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,103: Line 1,103:
╚════════════════════════════════════════════════════════════════════════════════════════╝
╚════════════════════════════════════════════════════════════════════════════════════════╝
</pre>
</pre>
<lang rexx>/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/
<syntaxhighlight lang="rexx">/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/
@usa.=; @usa.0=0; $='@USA.' /*initialize array and first value.*/
@usa.=; @usa.0=0; $='@USA.' /*initialize array and first value.*/
@usa.0=@usa.0 + 1 /*bump the unique number for usage.*/
@usa.0=@usa.0 + 1 /*bump the unique number for usage.*/
Line 1,136: Line 1,136:
call value $ || @usa.0'.upHist' , userid() date() time()
call value $ || @usa.0'.upHist' , userid() date() time()
end
end
return</lang>
return</syntaxhighlight>
{{out|output|text=&nbsp; (data used is within the REXX program):}}
{{out|output|text=&nbsp; (data used is within the REXX program):}}
<pre>
<pre>
Line 1,155: Line 1,155:


===version 2===
===version 2===
<lang rexx>/* REXX ***************************************************************
<syntaxhighlight lang="rexx">/* REXX ***************************************************************
* 17.05.2013 Walter Pachl
* 17.05.2013 Walter Pachl
* should work with every REXX.
* should work with every REXX.
Line 1,189: Line 1,189:
Say copies('-',40)
Say copies('-',40)
End
End
Return</lang>
Return</syntaxhighlight>
<pre> name --> FSF Inc.
<pre> name --> FSF Inc.
addr --> 51 Franklin Street
addr --> 51 Franklin Street
Line 1,205: Line 1,205:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : Table creation/Postal addresses
# Project : Table creation/Postal addresses


Line 1,221: Line 1,221:


sqlite_execute(oSQLite,sql)
sqlite_execute(oSQLite,sql)
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
Line 1,227: Line 1,227:
PStore implements a persistent key store with transactions. This is a NoSQL database. Each transaction reads the entire database into memory, and then writes it again, so PStore is not good for large databases.
PStore implements a persistent key store with transactions. This is a NoSQL database. Each transaction reads the entire database into memory, and then writes it again, so PStore is not good for large databases.


<lang ruby>require 'pstore'
<syntaxhighlight lang="ruby">require 'pstore'
require 'set'
require 'set'


Line 1,236: Line 1,236:
db[:next] ||= 0 # Next available Address#id
db[:next] ||= 0 # Next available Address#id
db[:ids] ||= Set[] # Set of all ids in db
db[:ids] ||= Set[] # Set of all ids in db
end</lang>
end</syntaxhighlight>


To put an Address inside this PStore:
To put an Address inside this PStore:


<lang ruby>db.transaction do
<syntaxhighlight lang="ruby">db.transaction do
id = (db[:next] += 1)
id = (db[:next] += 1)
db[id] = Address.new(id,
db[id] = Address.new(id,
Line 1,246: Line 1,246:
"Washington", "DC", 20500)
"Washington", "DC", 20500)
db[:ids].add id
db[:ids].add id
end</lang>
end</syntaxhighlight>


===With SQLite===
===With SQLite===
Line 1,252: Line 1,252:


{{libheader|sqlite3-ruby}}
{{libheader|sqlite3-ruby}}
<lang ruby>require 'sqlite3'
<syntaxhighlight lang="ruby">require 'sqlite3'


db = SQLite3::Database.new(':memory:')
db = SQLite3::Database.new(':memory:')
Line 1,263: Line 1,263:
addrZIP TEXT NOT NULL
addrZIP TEXT NOT NULL
)
)
")</lang>
")</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
AQLite
AQLite
<lang runbasic>sqliteconnect #mem, ":memory:" ' make handle #mem
<syntaxhighlight lang="runbasic">sqliteconnect #mem, ":memory:" ' make handle #mem
mem$ = "
mem$ = "
CREATE TABLE address (
CREATE TABLE address (
Line 1,276: Line 1,276:
addrZIP TEXT NOT NULL
addrZIP TEXT NOT NULL
)"
)"
#mem execute(mem$)</lang>
#mem execute(mem$)</syntaxhighlight>


=={{header|SAS}}==
=={{header|SAS}}==
<lang sql>
<syntaxhighlight lang="sql">


PROC SQL;
PROC SQL;
Line 1,291: Line 1,291:
)
)
;QUIT;
;QUIT;
</syntaxhighlight>
</lang>


=={{header|Scheme}}==
=={{header|Scheme}}==
Line 1,299: Line 1,299:
This example works with Chicken Scheme, using its sql-de-lite library:
This example works with Chicken Scheme, using its sql-de-lite library:


<lang scheme>
<syntaxhighlight lang="scheme">
(use sql-de-lite)
(use sql-de-lite)


Line 1,316: Line 1,316:


(close-database *db*) ; finally, close database
(close-database *db*) ; finally, close database
</syntaxhighlight>
</lang>


=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Perl}}
{{trans|Perl}}
<lang ruby>require('DBI');
<syntaxhighlight lang="ruby">require('DBI');


var db = %s'DBI'.connect('DBI:mysql:database:server','login','password');
var db = %s'DBI'.connect('DBI:mysql:database:server','login','password');
Line 1,336: Line 1,336:


var exec = db.prepare(statment);
var exec = db.prepare(statment);
exec.execute;</lang>
exec.execute;</syntaxhighlight>


=={{header|SQL PL}}==
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
{{works with|Db2 LUW}}
<lang sql pl>
<syntaxhighlight lang="sql pl">
CREATE TABLE Address (
CREATE TABLE Address (
addrID Integer generated by default as identity,
addrID Integer generated by default as identity,
Line 1,348: Line 1,348:
addrZIP Char(10) not null
addrZIP Char(10) not null
);
);
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 1,376: Line 1,376:
=={{header|SQLite}}==
=={{header|SQLite}}==
Purely in Sqlite3.
Purely in Sqlite3.
<lang sqlite3>
<syntaxhighlight lang="sqlite3">
CREATE TABLE address_USA (
CREATE TABLE address_USA (
address_ID INTEGER PRIMARY KEY,
address_ID INTEGER PRIMARY KEY,
Line 1,384: Line 1,384:
address_Zip INTEGER
address_Zip INTEGER
);
);
</syntaxhighlight>
</lang>


=={{header|Stata}}==
=={{header|Stata}}==
Line 1,392: Line 1,392:
Other possibilities include using the '''[https://www.stata.com/help.cgi?odbc odbc]''' command or a C or Java plugin to connect to a database. See the FAQ for more details: '''[https://www.stata.com/support/faqs/data-management/using-plugin-to-connect-to-database/ How do I connect to a database by using a Stata plugin?]'''.
Other possibilities include using the '''[https://www.stata.com/help.cgi?odbc odbc]''' command or a C or Java plugin to connect to a database. See the FAQ for more details: '''[https://www.stata.com/support/faqs/data-management/using-plugin-to-connect-to-database/ How do I connect to a database by using a Stata plugin?]'''.


<lang stata>clear
<syntaxhighlight lang="stata">clear
gen str8 addrid=""
gen str8 addrid=""
gen str50 street=""
gen str50 street=""
Line 1,398: Line 1,398:
gen str2 state=""
gen str2 state=""
gen str20 zip=""
gen str20 zip=""
save address</lang>
save address</syntaxhighlight>


=={{header|Tcl}}+SQLite==
=={{header|Tcl}}+SQLite==
{{libheader|SQLite}}
{{libheader|SQLite}}
<lang tcl>package require sqlite3
<syntaxhighlight lang="tcl">package require sqlite3


sqlite3 db address.db
sqlite3 db address.db
Line 1,413: Line 1,413:
addrZIP TEXT NOT NULL
addrZIP TEXT NOT NULL
)
)
}</lang>
}</syntaxhighlight>


=={{header|Transact-SQL}} (MSSQL)==
=={{header|Transact-SQL}} (MSSQL)==
<lang sql>CREATE TABLE #Address (
<syntaxhighlight lang="sql">CREATE TABLE #Address (
addrID int NOT NULL Identity(1,1) PRIMARY KEY,
addrID int NOT NULL Identity(1,1) PRIMARY KEY,
addrStreet varchar(50) NOT NULL ,
addrStreet varchar(50) NOT NULL ,
Line 1,423: Line 1,423:
addrZIP char(10) NOT NULL
addrZIP char(10) NOT NULL
)
)
drop table #Address</lang>
drop table #Address</syntaxhighlight>


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
Option Explicit


Line 1,441: Line 1,441:
.Close
.Close
End With
End With
</syntaxhighlight>
</lang>


=={{header|Visual FoxPro}}==
=={{header|Visual FoxPro}}==
<lang vfp>
<syntaxhighlight lang="vfp">
CLOSE DATABASES ALL
CLOSE DATABASES ALL
CREATE DATABASE usdata.dbc
CREATE DATABASE usdata.dbc
Line 1,456: Line 1,456:
OPEN DATABASE usdata.dbc
OPEN DATABASE usdata.dbc
USE address.dbf SHARED
USE address.dbf SHARED
</syntaxhighlight>
</lang>


=={{header|Wren}}==
=={{header|Wren}}==
Line 1,463: Line 1,463:
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
We use the same simple database format for this task as we did for the [[Table_creation#Wren]] task.
We use the same simple database format for this task as we did for the [[Table_creation#Wren]] task.
<lang ecmascript>import "/dynamic" for Enum, Tuple
<syntaxhighlight lang="ecmascript">import "/dynamic" for Enum, Tuple
import "/fmt" for Fmt
import "/fmt" for Fmt
import "/sort" for Cmp, Sort
import "/sort" for Cmp, Sort
Line 1,568: Line 1,568:
table.removeRecord(1)
table.removeRecord(1)
System.print("\nThe record with an id of 1 will be deleted, leaving:\n")
System.print("\nThe record with an id of 1 will be deleted, leaving:\n")
table.showRecords()</lang>
table.showRecords()</syntaxhighlight>


{{out}}
{{out}}
Line 1,607: Line 1,607:
{{trans|AWK}}
{{trans|AWK}}
Interact with SQLite via the command line.
Interact with SQLite via the command line.
<lang zkl>const NM="address.db";
<syntaxhighlight lang="zkl">const NM="address.db";
dbExec(NM,"create table address (street, city, state, zip);");</lang>
dbExec(NM,"create table address (street, city, state, zip);");</syntaxhighlight>
<lang zkl>fcn dbExec(db,qry){ dbErrorCheck(dbMakeQuery(db,qry),String(db," : ",qry)) }
<syntaxhighlight lang="zkl">fcn dbExec(db,qry){ dbErrorCheck(dbMakeQuery(db,qry),String(db," : ",qry)) }
fcn dbMakeQuery(db,qry){
fcn dbMakeQuery(db,qry){
qry=dbEscapeQuery(qry) + ";";
qry=dbEscapeQuery(qry) + ";";
Line 1,624: Line 1,624:
throw(Exception.IOError(listOfStrings.concat().strip()));
throw(Exception.IOError(listOfStrings.concat().strip()));
True
True
}</lang>
}</syntaxhighlight>