Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=#0000ff]/********************************************/[/color]
[COLOR=#0000ff]/* Reading records and fields from database */[/color]
[COLOR=#0000ff]/********************************************/[/color]
[COLOR=#0000ff]/*## Enter Login-Data */[/color]
csebk [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]raw_input([/color][COLOR=#ff00ff]"AS/400 name : "[/color][COLOR=#008080])[/color]
schema [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]raw_input([/color][COLOR=#ff00ff]"DB schema : "[/color][COLOR=#008080])[/color]
userid [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]raw_input([/color][COLOR=#ff00ff]"User Id : "[/color][COLOR=#008080])[/color]
[COLOR=#0000ff]/* Using getpass for getting password */[/color]
pwd [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]getpass([/color][COLOR=#ff00ff]"Password : "[/color][COLOR=#008080])[/color]
[COLOR=#0000ff]/*## using ADO */[/color]
[COLOR=#0000ff]/* Connection String */[/color]
connection_string[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]"PROVIDER=IBMDA400; DATA SOURCE="[/color]csebk[COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"; USER ID="[/color]userid[COLOR=#ff00ff]"; PASSWORD="[/color]pwd[COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"; DEFAULT COLLECTION = "[/color]schema
[COLOR=#0000ff]/* Open ADO connection */[/color]
connection [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].OLEObject[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]New[/color][COLOR=#008080]([/color][COLOR=#ff00ff]"ADODB.Connection"[/color][COLOR=#008080])[/color]
connection[COLOR=#804040][b]~[/b][/color][COLOR=#008080]open[/color][COLOR=#008080]([/color]connection_string[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Create an instance of an ADO Recordset */[/color]
recordset [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].OLEObject[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]New[/color][COLOR=#008080]([/color][COLOR=#ff00ff]"ADODB.Recordset"[/color][COLOR=#008080])[/color]
sql_stmt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"select * "[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"from P001800V "[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"where OBEC like '%Mesto%'"[/color]
[COLOR=#0000ff]/* Open the recordset, using an SQL statement and the existing ADO connection */[/color]
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]open[/color][COLOR=#008080]([/color]sql_stmt[COLOR=#804040][b],[/b][/color] connection[COLOR=#804040][b],[/b][/color] 1[COLOR=#804040][b],[/b][/color] 3[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Create and populate an array of field names */[/color]
fields_count [COLOR=#804040][b]=[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Count[/color]
fields [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] fields_count
[COLOR=#804040][b]if[/b][/color] j [COLOR=#804040][b]<[/b][/color] fields_count [COLOR=#804040][b]then[/b][/color]
fields [COLOR=#804040][b]=[/b][/color] fields [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#008080]([/color]j[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Name[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]" "[/color]
[COLOR=#804040][b]else[/b][/color]
fields [COLOR=#804040][b]=[/b][/color] fields [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#008080]([/color]j[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Name[/color]
[COLOR=#804040][b]end[/b][/color]
csv_file [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"mesta.csv"[/color]
[COLOR=#0000ff]/* Open CSV file */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Now writing data to CSV file '"[/color] [COLOR=#804040][b]||[/b][/color] csv_file [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]"'.."[/color]
[COLOR=#0000ff]/* Header line */[/color]
line [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]translate([/color]fields[COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]";"[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]" "[/color][COLOR=#008080])[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file[COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] 1
[COLOR=#0000ff]/* Data lines */[/color]
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]([/color][COLOR=#804040][b]\[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]EOF[/color][COLOR=#008080])[/color]
line [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] [COLOR=#008080]words([/color]fields[COLOR=#008080])[/color]
fieldname [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]word([/color]fields[COLOR=#804040][b],[/b][/color] j[COLOR=#008080])[/color]
[COLOR=#0000ff]/* join field values into string */[/color]
[COLOR=#804040][b]if[/b][/color] j [COLOR=#804040][b]<[/b][/color] fields_count [COLOR=#804040][b]then[/b][/color]
line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Item[/color][COLOR=#008080]([/color]fieldname[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Value[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]";"[/color]
[COLOR=#804040][b]else[/b][/color]
line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Item[/color][COLOR=#008080]([/color]fieldname[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Value[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file[COLOR=#804040][b],[/b][/color] line
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]MoveNext[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"..done."[/color]
[COLOR=#0000ff]/* Close CSV file */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file
[COLOR=#0000ff]/* Close RecordSet */[/color]
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]close[/color][COLOR=#008080]()[/color]
[COLOR=#0000ff]/* Close Connection */[/color]
connection[COLOR=#804040][b]~[/b][/color][COLOR=#008080]close[/color][COLOR=#008080]()[/color]
[COLOR=#804040][b]exit[/b][/color]
[COLOR=#0000ff]/**************** Functions ****************/[/color]
[COLOR=#008080]raw_input[/color][COLOR=#804040][b]:[/b][/color] [COLOR=#804040][b]procedure[/b][/color]
[COLOR=#0000ff]/* function raw_input() */[/color]
[COLOR=#804040][b]use arg[/b][/color] prompt
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color] prompt
[COLOR=#804040][b]parse pull[/b][/color] inp
[COLOR=#804040][b]return[/b][/color] inp
[COLOR=#008080]getpass[/color][COLOR=#804040][b]:[/b][/color] [COLOR=#804040][b]procedure[/b][/color]
[COLOR=#0000ff]/* print the prompt */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color] [COLOR=#008080]arg([/color]1[COLOR=#008080])[/color]
[COLOR=#0000ff]/* define some ASCII constants */[/color]
EnterKey [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'0D'X[/color] [COLOR=#0000ff]/* ASCII Enter i.e. Carriage Return */[/color]
BackSpaceKey [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'08'X[/color] [COLOR=#0000ff]/* ASCII BackSpace */[/color]
BeepSound [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'07'X[/color] [COLOR=#0000ff]/* ASCII Beep sound */[/color]
pwd [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]''[/color]
[COLOR=#804040][b]do forever [/b][/color]
char [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]SysGetKey([/color][COLOR=#ff00ff]'NOECHO'[/color][COLOR=#008080])[/color]
[COLOR=#804040][b]if[/b][/color] char[COLOR=#804040][b]=[/b][/color]EnterKey [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]leave[/b][/color]
[COLOR=#804040][b]if[/b][/color] char[COLOR=#804040][b]=[/b][/color]BackSpaceKey [COLOR=#804040][b]then[/b][/color]
[COLOR=#804040][b]if[/b][/color] [COLOR=#008080]length([/color]pwd[COLOR=#008080])[/color][COLOR=#804040][b]>[/b][/color]0 [COLOR=#804040][b]then[/b][/color]
[COLOR=#804040][b]do[/b][/color]
pwd[COLOR=#804040][b]=[/b][/color][COLOR=#008080]substr([/color]pwd[COLOR=#804040][b],[/b][/color]1[COLOR=#804040][b],[/b][/color][COLOR=#008080]length([/color]pwd[COLOR=#008080])[/color][COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Move Cursor Back */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color] BackSpaceKey
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]' '[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color] BackSpaceKey
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]else[/b][/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color] BeepSound
[COLOR=#804040][b]else[/b][/color]
[COLOR=#804040][b]do [/b][/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]charout[/color] [COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]'*'[/color]
pwd [COLOR=#804040][b]=[/b][/color] pwd[COLOR=#ff00ff]''[/color]char
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]say[/b][/color]
[COLOR=#804040][b]return[/b][/color] pwd
[COLOR=#0000ff]/********************************************/[/color]
[COLOR=#0000ff]/* Reading records and fields from database */[/color]
[COLOR=#0000ff]/********************************************/[/color]
[COLOR=#0000ff]/*## using ADO */[/color]
[COLOR=#0000ff]/* Connection String */[/color]
connection_string[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]"PROVIDER=Microsoft.ACE.OLEDB.12.0"[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"; DATA SOURCE=Exercise.accdb"[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"; Persist Security Info=False;"[/color]
[COLOR=#0000ff]/* Open ADO connection */[/color]
connection [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].OLEObject[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]New[/color][COLOR=#008080]([/color][COLOR=#ff00ff]"ADODB.Connection"[/color][COLOR=#008080])[/color]
connection[COLOR=#804040][b]~[/b][/color][COLOR=#008080]open[/color][COLOR=#008080]([/color]connection_string[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Create an instance of an ADO Recordset */[/color]
recordset [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].OLEObject[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]New[/color][COLOR=#008080]([/color][COLOR=#ff00ff]"ADODB.Recordset"[/color][COLOR=#008080])[/color]
sql_stmt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"select * "[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"from P001800V "[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"where OBEC like '%Mesto%'"[/color]
[COLOR=#0000ff]/* Open the recordset, using an SQL statement and the existing ADO connection */[/color]
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]open[/color][COLOR=#008080]([/color]sql_stmt[COLOR=#804040][b],[/b][/color] connection[COLOR=#804040][b],[/b][/color] 1[COLOR=#804040][b],[/b][/color] 3[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Create and populate an array of field names */[/color]
fields_count [COLOR=#804040][b]=[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Count[/color]
fields [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] fields_count
[COLOR=#804040][b]if[/b][/color] j [COLOR=#804040][b]<[/b][/color] fields_count [COLOR=#804040][b]then[/b][/color]
fields [COLOR=#804040][b]=[/b][/color] fields [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#008080]([/color]j[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Name[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]" "[/color]
[COLOR=#804040][b]else[/b][/color]
fields [COLOR=#804040][b]=[/b][/color] fields [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#008080]([/color]j[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Name[/color]
[COLOR=#804040][b]end[/b][/color]
csv_file [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"mesta.csv"[/color]
[COLOR=#0000ff]/* Open CSV file */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Now writing data to CSV file '"[/color] [COLOR=#804040][b]||[/b][/color] csv_file [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]"'.."[/color]
[COLOR=#0000ff]/* Header line */[/color]
line [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]translate([/color]fields[COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]";"[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]" "[/color][COLOR=#008080])[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file[COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] 1
[COLOR=#0000ff]/* Data lines */[/color]
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]([/color][COLOR=#804040][b]\[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]EOF[/color][COLOR=#008080])[/color]
line [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] [COLOR=#008080]words([/color]fields[COLOR=#008080])[/color]
fieldname [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]word([/color]fields[COLOR=#804040][b],[/b][/color] j[COLOR=#008080])[/color]
[COLOR=#0000ff]/* join field values into string */[/color]
[COLOR=#804040][b]if[/b][/color] j [COLOR=#804040][b]<[/b][/color] fields_count [COLOR=#804040][b]then[/b][/color]
line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Item[/color][COLOR=#008080]([/color]fieldname[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Value[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]";"[/color]
[COLOR=#804040][b]else[/b][/color]
line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Item[/color][COLOR=#008080]([/color]fieldname[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Value[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file[COLOR=#804040][b],[/b][/color] line
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]MoveNext[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"..done."[/color]
[COLOR=#0000ff]/* Close CSV file */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file
[COLOR=#0000ff]/* Close RecordSet */[/color]
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]close[/color][COLOR=#008080]()[/color]
[COLOR=#0000ff]/* Close Connection */[/color]
connection[COLOR=#804040][b]~[/b][/color][COLOR=#008080]close[/color][COLOR=#008080]()[/color]
[COLOR=#804040][b]exit[/b][/color]
[COLOR=#0000ff]/********************************************/[/color]
[COLOR=#0000ff]/* Reading records and fields from database */[/color]
[COLOR=#0000ff]/********************************************/[/color]
[COLOR=#0000ff]/*## using ADO */[/color]
[COLOR=#0000ff]/* Connection String */[/color]
connection_string[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]"PROVIDER=MSDASQL; DRIVER={SQLite3 ODBC Driver}"[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"; DATABASE=c:\00_mikrom\Work\PIGS_DB"[/color]
[COLOR=#0000ff]/* Open ADO connection */[/color]
connection [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].OLEObject[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]New[/color][COLOR=#008080]([/color][COLOR=#ff00ff]"ADODB.Connection"[/color][COLOR=#008080])[/color]
connection[COLOR=#804040][b]~[/b][/color][COLOR=#008080]open[/color][COLOR=#008080]([/color]connection_string[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Create an instance of an ADO Recordset */[/color]
recordset [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].OLEObject[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]New[/color][COLOR=#008080]([/color][COLOR=#ff00ff]"ADODB.Recordset"[/color][COLOR=#008080])[/color]
sql_stmt [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"select * "[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"from GUINEA_PIGS "[/color][COLOR=#804040][b]||[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
[COLOR=#ff00ff]"where NAME like '%Sisi%'"[/color]
[COLOR=#0000ff]/* Open the recordset, using an SQL statement and the existing ADO connection */[/color]
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]open[/color][COLOR=#008080]([/color]sql_stmt[COLOR=#804040][b],[/b][/color] connection[COLOR=#804040][b],[/b][/color] 1[COLOR=#804040][b],[/b][/color] 3[COLOR=#008080])[/color]
[COLOR=#0000ff]/* Create and populate an array of field names */[/color]
fields_count [COLOR=#804040][b]=[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Count[/color]
fields [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] fields_count
[COLOR=#804040][b]if[/b][/color] j [COLOR=#804040][b]<[/b][/color] fields_count [COLOR=#804040][b]then[/b][/color]
fields [COLOR=#804040][b]=[/b][/color] fields [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#008080]([/color]j[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Name[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]" "[/color]
[COLOR=#804040][b]else[/b][/color]
fields [COLOR=#804040][b]=[/b][/color] fields [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#008080]([/color]j[COLOR=#804040][b]-[/b][/color]1[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Name[/color]
[COLOR=#804040][b]end[/b][/color]
csv_file [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"pigs.csv"[/color]
[COLOR=#0000ff]/* Open CSV file */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"Now writing data to CSV file '"[/color] [COLOR=#804040][b]||[/b][/color] csv_file [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]"'.."[/color]
[COLOR=#0000ff]/* Header line */[/color]
line [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]translate([/color]fields[COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]";"[/color][COLOR=#804040][b],[/b][/color][COLOR=#ff00ff]" "[/color][COLOR=#008080])[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file[COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] 1
[COLOR=#0000ff]/* Data lines */[/color]
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]([/color][COLOR=#804040][b]\[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]EOF[/color][COLOR=#008080])[/color]
line [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] [COLOR=#008080]words([/color]fields[COLOR=#008080])[/color]
fieldname [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]word([/color]fields[COLOR=#804040][b],[/b][/color] j[COLOR=#008080])[/color]
[COLOR=#0000ff]/* join field values into string */[/color]
[COLOR=#804040][b]if[/b][/color] j [COLOR=#804040][b]<[/b][/color] fields_count [COLOR=#804040][b]then[/b][/color]
line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Item[/color][COLOR=#008080]([/color]fieldname[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Value[/color] [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]";"[/color]
[COLOR=#804040][b]else[/b][/color]
line [COLOR=#804040][b]=[/b][/color] line [COLOR=#804040][b]||[/b][/color] recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]Fields[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Item[/color][COLOR=#008080]([/color]fieldname[COLOR=#008080])[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]Value[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file[COLOR=#804040][b],[/b][/color] line
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]MoveNext[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"..done."[/color]
[COLOR=#0000ff]/* Close CSV file */[/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] csv_file
[COLOR=#0000ff]/* Close RecordSet */[/color]
recordset[COLOR=#804040][b]~[/b][/color][COLOR=#008080]close[/color][COLOR=#008080]()[/color]
[COLOR=#0000ff]/* Close Connection */[/color]
connection[COLOR=#804040][b]~[/b][/color][COLOR=#008080]close[/color][COLOR=#008080]()[/color]
[COLOR=#804040][b]exit[/b][/color]