110 lines
3.0 KiB
C
110 lines
3.0 KiB
C
/*
|
|
* Copyright (C) 2005 Walter Garrote
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
* as published by the Free Software Foundation; either version 2.1,
|
|
* or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; see the file COPYING.LIB. If
|
|
* not, write to the Free Software Foundation, Inc., 59 Temple Place,
|
|
* Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include <htconfig.h>
|
|
|
|
#ifdef USE_MYSQL_GATEWAY
|
|
#include <mysqld_error.h>
|
|
#include <mysql.h>
|
|
MYSQL *sql_conn;
|
|
#endif
|
|
|
|
#ifdef USE_PGSQL_GATEWAY
|
|
#include <libpq-fe.h>
|
|
PGconn *sql_conn;
|
|
#endif
|
|
|
|
|
|
unsigned char sql_server;
|
|
char *sql_fdsql;
|
|
char *sql_host;
|
|
char *sql_user;
|
|
char *sql_passwd;
|
|
char *sql_db;
|
|
|
|
struct file_sql {
|
|
char *original_name;
|
|
char *table_name;
|
|
struct file_sql *next;
|
|
};
|
|
|
|
struct fields_sql {
|
|
struct altkey_desc *alt;
|
|
int level;
|
|
char *name;
|
|
char type;
|
|
int size;
|
|
int decimals;
|
|
int index;
|
|
int unique;
|
|
struct fields_sql *next;
|
|
};
|
|
|
|
struct keys_sql {
|
|
char *name;
|
|
int type; // 1-Primary, 2-Alternate unique, 3-Alternate duplicate
|
|
char *fields;
|
|
struct keys_sql *next;
|
|
};
|
|
|
|
struct fd_sql {
|
|
#ifdef USE_MYSQL_GATEWAY
|
|
MYSQL_RES *sql_result;
|
|
#endif
|
|
#ifdef USE_PGSQL_GATEWAY
|
|
PGresult *sql_result;
|
|
#endif
|
|
int row;
|
|
struct file_desc *file;
|
|
char *name;
|
|
struct fields_sql *fields;
|
|
struct keys_sql *keys;
|
|
struct fd_sql *next;
|
|
};
|
|
|
|
extern int bDecimalComma;
|
|
|
|
int tcob_read_tinysql(void);
|
|
int tcob_sql_int(char *campo);
|
|
char * tcob_sql_table_name(char *fd);
|
|
int tcob_sql_read_def(char *fd, struct file_desc *f);
|
|
int tcob_sql_read_fd(char *path, char *table, struct file_desc *f);
|
|
int tcob_sql_read_select(char *path, char *table);
|
|
void clean_read_line(char *linha, char *linhar, int ponto);
|
|
void tcob_move_value(char *variavel, char *value);
|
|
void create_mount_files(char *file_name, char *table_name);
|
|
|
|
struct fd_sql * search_table(struct file_desc *fd);
|
|
int put_value_query(struct fields_sql *fld, char *record, int p, char *query);
|
|
int create_sql_db(char *fd);
|
|
int insert_sql_db(struct file_desc *f, char *record);
|
|
int start_sql_db(struct file_desc *f, char *record, int cond, char *key_ptr);
|
|
int read_sql_db(struct file_desc *fd, char *record);
|
|
int readnext_sql_db(struct file_desc *fd, char *record);
|
|
int readprevious_sql_db(struct file_desc *fd, char *record);
|
|
int delete_sql_db(struct file_desc *fd, char *record);
|
|
int update_sql_db(struct file_desc *fd, char *record);
|
|
void put_value_record(struct fields_sql *fld, char *record, int p, char *row);
|
|
int connect_sql_db(void);
|
|
int query_sql_db(struct fd_sql *pfd, char *query, int store_result);
|
|
void free_sql_db(struct fd_sql *pfd);
|
|
int close_sql_table(struct file_desc *f);
|
|
int close_sql_db(void);
|
|
int read_offset_db(struct fd_sql *pfd, char *record);
|