4 #include <grass/dbmi.h>
5 #include <grass/form.h>
27 F_generate(
char *drvname,
char *dbname,
char *tblname,
char *key,
int keyval,
28 char *frmname,
char *frmmapset,
29 int edit_mode,
int format,
char **form)
31 int col, ncols, ctype, sqltype, more;
32 char buf[5000], buf1[100];
34 dbString sql, html, str;
45 static char *encoding_list[] = {
64 "F_generate(): drvname = '%s', dbname = '%s'\n tblname = '%s', key = '%s', keyval = %d\n"
65 " form = '%s', form_mapset = '%s'\n edit_mode = %d",
66 drvname, dbname, tblname, key, keyval, frmname, frmmapset,
77 sprintf(buf,
"Cannot open driver '%s'<BR>",
90 sprintf(buf,
"Cannot open database '%s' by driver '%s'<BR>",
101 sprintf(buf,
"select * from %s where %s = %d", tblname, key, keyval);
109 "Cannot open select cursor:<BR>'%s'<BR>on database '%s' by driver '%s'<BR>",
115 G_debug(2,
"Select Cursor opened");
119 if (
db_fetch(&cursor, DB_NEXT, &more) != DB_OK) {
124 *form =
G_store(
"Cannot fetch next record");
130 if (format == F_HTML) {
131 *form =
G_store(
"No record selected.<BR>");
134 *form =
G_store(
"No record selected.");
141 if (format == F_HTML) {
142 if (edit_mode == F_EDIT) {
145 sprintf(buf,
"<INPUT type=hidden name=%s value=\"%s\">",
152 sprintf(buf,
"<INPUT type=hidden value=\"%s\" name=%s>",
156 sprintf(buf,
"<INPUT type=hidden name=%s value=\"%s\">",
160 sprintf(buf,
"<INPUT type=hidden name=%s value=\"%s\">",
167 for (col = 0; col < ncols; col++) {
177 if (edit_mode == F_VIEW) {
178 sprintf(buf,
"<B>%s : </B> %s <BR>",
190 "%s<BR> <INPUT type=hidden name=%s value=\"%s\">",
200 case DB_C_TYPE_DOUBLE:
203 case DB_C_TYPE_STRING:
206 case DB_C_TYPE_DATETIME:
211 "<INPUT type=text size=%s name=%s value=\"%s\"><BR>",
220 if (edit_mode == F_EDIT) {
222 "<HR> Assume data encoding as:<BR><BR><SELECT NAME=%s SIZE=4><HR><BR>",
227 while (encoding_list[i] !=
NULL) {
230 sprintf(buf,
"<OPTION VALUE=\"%s\" SELECTED>%s",
231 encoding_list[i], encoding_list[i]);
233 sprintf(buf,
"<OPTION VALUE=\"%s\">%s",
234 encoding_list[i], encoding_list[i]);
244 if (edit_mode == F_EDIT) {
249 for (col = 0; col < ncols; col++) {
dbColumn * db_get_table_column(dbTable *table, int n)
returns column structure for given table and column number
int F_generate(char *drvname, char *dbname, char *tblname, char *key, int keyval, char *frmname, char *frmmapset, int edit_mode, int format, char **form)
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int db_close_cursor(dbCursor *cursor)
Close cursor.
char * G__getenv(const char *name)
Get environment variable.
char * G_store(const char *s)
Copy string to allocated memory.
const char * db_get_column_name(dbColumn *column)
returns column name for given column
int db_shutdown_driver(dbDriver *driver)
Closedown the driver, and free the driver structure.
int db_close_database(dbDriver *driver)
Close database connection.
char * G_strdup(const char *string)
Copies the null-terminated string into a newly allocated string. The string is allocated using G_mall...
int db_get_column_length(dbColumn *column)
int db_convert_value_to_string(dbValue *value, int sqltype, dbString *string)
int db_append_string(dbString *x, const char *s)
int db_sqltype_to_Ctype(int sqltype)
int db_fetch(dbCursor *cursor, int position, int *more)
Fetch data.
dbTable * db_get_cursor_table(dbCursor *cursor)
int db_get_column_sqltype(dbColumn *column)
returns column sqltype for column (the function db_sqltype_name() returns sqltype description) ...
char * G_str_replace(char *buffer, const char *old_str, const char *new_str)
Replace all occurencies of old_str in buffer with new_str.
int db_get_table_number_of_columns(dbTable *table)
dbValue * db_get_column_value(dbColumn *column)
returns column value for given column structure
int db_set_handle(dbHandle *handle, const char *dbName, const char *dbSchema)
char * escape_tcl_string(char *input)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
char * db_get_string(dbString *x)
int G_debug(int level, const char *msg,...)
Print debugging message.
void db_init_handle(dbHandle *handle)
int db_set_string(dbString *x, const char *s)
int db_open_database(dbDriver *driver, dbHandle *handle)
Open database connection.
void db_free_string(dbString *x)
dbDriver * db_start_driver(const char *name)
Initialize a new dbDriver for db transaction.
int db_open_select_cursor(dbDriver *driver, dbString *select, dbCursor *cursor, int mode)
Open select cursor.
void db_init_string(dbString *x)
int G__read_env(void)
Initialize init array for G_VAR_GISRC.