Task

Create a table to store addresses.

You may assume that all the addresses to be stored will be located in the USA.   As such, you will need (in addition to a field holding a unique identifier) a field holding the street address, a field holding the city, a field holding the state code, and a field holding the zipcode.   Choose appropriate types for each field.

For non-database languages, show how you would open a connection to a database (your choice of which) and create an address table in it. You should follow the existing models here for how you would structure the table.




without js -- (file i/o)
include pSQLite.e
constant sqlcode = """
CREATE TABLE address (
 addrID     INTEGER PRIMARY KEY AUTOINCREMENT,
 addrStreet TEXT NOT NULL,
 addrCity   TEXT NOT NULL,
 addrState  TEXT NOT NULL,
 addrZIP    TEXT NOT NULL)"""
 
sqlite3 db = sqlite3_open("address.sqlite")
integer res = sqlite3_exec(db,sqlcode)
if res=SQLITE_OK then
    sqlite3_close(db)
else
    -- can show eg "sqlite3_exec error: 1 [table address already exists]"
    printf(1,"sqlite3_exec error: %d [%s]\n",{res,sqlite_last_exec_err})
end if
