OPTIONS "NOSOURCE"
create: PROCEDURE EXPOSE datasrcname odbc_tablename sql_all_colname. sql_coltype. sql_length. sql_scale.
guierr = "SYNTAX"
guiheading = 1
guicreatewindow(, -1)
display_column_names()
guisetctlplacement(guiwindow,,,,,,'NORMAL')
RETURN
destroy:
guidestroywindow()
RETURN
display_column_names:
IF POS('DB2', datasrcname) \== 0 THEN SIGNAL display_db2_names
IF POS('SQLITE', datasrcname) \== 0 THEN SIGNAL display_sqlite_names
RAISE SYNTAX 48 DESCRIPTION ("You must add code to extract column names and datatypes for" datasrcname)
display_db2_names:
DO i = 1 TO sql_all_colname.0
string = STRIP(sql_all_colname.i) '(' || STRIP(sql_coltype.i)
IF sql_coltype.i == 'DECIMAL' THEN
string = string sql_length.i || ',' || sql_scale.i || ')'
ELSE
string = string || ')'
guisendmsg('ODBC_Fields', 'ADDSTRING',, string)
END
RETURN
display_sqlite_names:
DO i = 1 TO sql_all_colname.0
guisendmsg('ODBC_Fields', 'ADDSTRING',, STRIP(sql_all_colname.i) '(' || STRIP(sql_coltype.i) || ')')
END
RETURN
wm_click_cancel:
guisendmsg(, "POST CLOSE")
RETURN
wm_click_odbc_insert:
guigetctlvalue()
SELECT
WHEN POS('DB2', datasrcname) \== 0 THEN
guiwake(make_db2_insert_cmd())
WHEN POS('SQLITE', datasrcname) \== 0 THEN
guiwake(make_sqlite_insert_cmd())
OTHERWISE
RAISE SYNTAX 48 DESCRIPTION ("Need to add code to make an SQL command to insert a row for" datasrcname)
END
RETURN
make_db2_insert_cmd:
string = 'Insert into' database || '.' || odbc_tablename' values ('
split_into_stem('0D0A'x, odbc_values, temp.)
IF check_nr_rows(temp.) == 1 THEN RETURN ""
DO i = 1 TO temp.0
coltype = ' ' || TRANSLATE(sql_coltype.i)
SELECT
WHEN POS(' TIMESTMP',coltype) \== 0 | POS('(TIMESTMP',coltype) \== 0 THEN DO
IF temp.i = "" THEN
new_value = ",current timestamp"
ELSE
new_value = ",'"temp.i"'"
END
WHEN POS(' TIME',coltype) \== 0 | POS('(TIME',coltype) \== 0 THEN DO
IF temp.i = "" THEN
new_value = ",current time"
ELSE
new_value = ",'"STRIP(temp.i)"'"
END
WHEN POS(' DATE',coltype) \== 0 | POS('(DATE',coltype) \== 0 THEN DO
IF temp.i = "" THEN
new_value = ",current date"
ELSE
new_value = ",'"temp.i"'"
END
WHEN POS(' CHAR',coltype) \== 0 | POS('(CHAR',coltype) \== 0 THEN
new_value = ",'"STRIP(temp.i,'T')"'"
WHEN POS(' VARCHAR',coltype) \== 0 | POS('(VARCHAR',coltype) \== 0 THEN
new_value = ",'"STRIP(temp.i,'T')"'"
OTHERWISE
new_value = ","temp.i
END
IF i == 1 THEN
new_value = SUBSTR(new_value, 2)
string = string||new_value
END
string = string || ')'
RETURN string
make_sqlite_insert_cmd:
string = 'Insert into' odbc_tablename 'values ('
split_into_stem('0D0A'x, odbc_values, temp.)
IF check_nr_rows(temp.) == 1 THEN RETURN ""
DO i = 1 TO temp.0
coltype = ' ' || TRANSLATE(sql_coltype.i)
SELECT
WHEN POS(' TIMESTAMP',coltype) \== 0 | POS('(TIMESTAMP',coltype) \== 0 THEN DO
IF temp.i = "" THEN
new_value = ",datetime('NOW')"
ELSE
new_value = ",'"temp.i"'"
END
WHEN POS(' TIME',coltype) \== 0 | POS('(TIME',coltype) \== 0 THEN DO
IF temp.i = "" THEN
new_value = ",TIME('NOW')"
ELSE
new_value = ",'"STRIP(temp.i)"'"
END
WHEN POS(' DATE',coltype) \== 0 | POS('(DATE',coltype) \== 0 THEN DO
IF temp.i = "" THEN
new_value = ",DATE('NOW')"
ELSE
new_value = ",'"temp.i"'"
END
WHEN POS(' CHAR',coltype) \== 0 | POS('(CHAR',coltype) \== 0 THEN
new_value = ",'"STRIP(temp.i,'T')"'"
WHEN POS(' VARCHAR',coltype) \== 0 | POS('(VARCHAR',coltype) \== 0 THEN
new_value = ",'"STRIP(temp.i,'T')"'"
OTHERWISE
new_value = "," || temp.i
END
IF i == 1 THEN
new_value = SUBSTR(new_value, 2)
string = string || new_value
END
string = string || ')'
RETURN string
check_nr_rows:
SELECT
WHEN temp.0 = sql_all_colname.0 THEN
RETURN 0
WHEN temp.0 < sql_all_colname.0 THEN DO
y = temp.0 + 1
DO i = y TO sql_all_colname.0
temp.i = ""
END
temp.0 = sql_all_colname.0
END
OTHERWISE DO
guisay('Too many rows specified for this table', "OK|STOP")
RETURN 1
END
END
RETURN 0 |
|