gambas-source-code/main/lib/db/gb.db.h

254 lines
7.5 KiB
C
Raw Normal View History

/***************************************************************************
gb.db.h
The Gambas Database component Interface
(c) 2000-2007 Benoit Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#ifndef __GB_DB_H
#define __GB_DB_H
#include "gambas.h"
#define DB_INTERFACE_VERSION 1
typedef
struct {
char *type;
char *host;
char *port;
char *name;
char *user;
char *password;
int options;
}
DB_DESC;
/* LIMIT position */
#define DB_LIMIT_NONE 0
#define DB_LIMIT_AT_BEGIN 1
#define DB_LIMIT_AT_END 2
typedef
struct {
void *handle; /* Connection handle */
int version; /* Version of the database system */
char *charset; /* Charset used by the database */
void *data; /* Can be used by the driver for storing its own private data */
int error; /* Last SQL error code raise by a query */
unsigned ignore_case : 1; /* If table, field and index names are case sensitive */
struct {
unsigned no_table_type : 1; /* Tables do not have types */
unsigned no_serial : 1; /* Serial fields are not supported */
unsigned no_blob : 1; /* Blob fields are not supported */
unsigned no_seek : 1; /* Cannot seek anywhere in a Result */
unsigned no_nest : 1; /* Cannot nest transactions */
unsigned no_case : 1; /* If table, field and index names can be case sensitive or not */
}
flags;
struct {
const char *keyword; /* keyword for limiting the result of a query */
int pos; /* position of 'limit' keyword */
}
limit;
const char *db_name_char; /* These characters are allowed in a database name */
}
DB_DATABASE;
typedef
void *DB_RESULT;
typedef
struct _DB_FIELD {
struct _DB_FIELD *next;
char *name;
GB_TYPE type; /* gambas field type */
int length; /* max length for text fields (0 = no limit) */
GB_VARIANT_VALUE def; /* default value */
}
DB_FIELD;
typedef
struct {
char *table;
int nfield;
int nindex;
DB_FIELD *field;
int *index;
}
DB_INFO;
typedef
struct {
char *name;
char *fields; /* list of index fields separated by commas */
int unique; /* index is unique */
int primary; /* primary index */
}
DB_INDEX;
typedef
struct {
char *name;
char *password;
int admin; /* user is a superuser */
}
DB_USER;
typedef
struct {
GB_BASE ob;
char *data;
int length;
int constant;
}
DB_BLOB;
typedef
void (*DB_FORMAT_CALLBACK)(const char *, int);
typedef
void (*DB_SUBST_CALLBACK)(int, char **, int *, char);
typedef
struct {
const char *name;
int (*Open)(DB_DESC *desc, DB_DATABASE *db);
void (*Close)(DB_DATABASE *db);
int (*Format)(GB_VALUE *val, DB_FORMAT_CALLBACK add);
void (*FormatBlob)(DB_BLOB *blob, DB_FORMAT_CALLBACK add);
int (*Exec)(DB_DATABASE *db, const char *, DB_RESULT *result, const char *err);
int (*Begin)(DB_DATABASE *db);
int (*Commit)(DB_DATABASE *db);
int (*Rollback)(DB_DATABASE *db);
const char *(*GetQuote)(void);
struct {
void (*Init)(DB_RESULT result, DB_INFO *info, int *count);
int (*Fill)(DB_DATABASE *db, DB_RESULT result, int pos, GB_VARIANT_VALUE *buffer, int next);
void (*Blob)(DB_RESULT result, int pos, int field, DB_BLOB *blob);
void (*Release)(DB_RESULT result, DB_INFO *info);
struct {
GB_TYPE (*Type)(DB_RESULT result, int index);
char *(*Name)(DB_RESULT result, int index);
int (*Index)(DB_RESULT result, const char *name, DB_DATABASE *db);
int (*Length)(DB_RESULT result, int index);
}
Field;
}
Result;
struct {
int (*Exist)(DB_DATABASE *db, const char *table, const char *field);
int (*List)(DB_DATABASE *db, const char *table, char ***fields);
int (*Info)(DB_DATABASE *db, const char *table, const char *field, DB_FIELD *info);
}
Field;
struct {
int (*Init)(DB_DATABASE *db, const char *table, DB_INFO *info);
int (*Index)(DB_DATABASE *db, const char *table, DB_INFO *info);
void (*Release)(DB_DATABASE *db, DB_INFO *info);
int (*Exist)(DB_DATABASE *db, const char *table);
int (*List)(DB_DATABASE *db, char ***tables);
int (*PrimaryKey)(DB_DATABASE *db, const char *table, char ***primary);
int (*IsSystem)(DB_DATABASE *db, const char *table);
char *(*Type)(DB_DATABASE *db, const char *table, const char *type);
int (*Delete)(DB_DATABASE *db, const char *table);
int (*Create)(DB_DATABASE *db, const char *table, DB_FIELD *fields, char **primary, const char *tabletype);
}
Table;
struct {
int (*Exist)(DB_DATABASE *db, const char *table, const char *index);
int (*List)(DB_DATABASE *db, const char *table, char ***indexes);
int (*Info)(DB_DATABASE *db, const char *table, const char *index, DB_INDEX *info);
int (*Delete)(DB_DATABASE *db, const char *table, const char *index);
int (*Create)(DB_DATABASE *db, const char *table, const char *index, DB_INDEX *info);
}
Index;
struct {
int (*Exist)(DB_DATABASE *db, const char *name);
int (*List)(DB_DATABASE *db, char ***names);
int (*IsSystem)(DB_DATABASE *db, const char *name);
int (*Delete)(DB_DATABASE *db, const char *name);
int (*Create)(DB_DATABASE *db, const char *name);
}
Database;
struct {
int (*Exist)(DB_DATABASE *db, const char *user);
int (*List)(DB_DATABASE *db, char ***users);
int (*Info)(DB_DATABASE *db, const char *user, DB_USER *info);
int (*Delete)(DB_DATABASE *db, const char *user);
int (*Create)(DB_DATABASE *db, const char *user, DB_USER *info);
int (*SetPassword)(DB_DATABASE *db, const char *user, const char *password);
}
User;
}
DB_DRIVER;
typedef
struct {
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
intptr_t version;
void (*Register)(DB_DRIVER *);
void (*Format)(DB_DRIVER *, GB_VALUE *, DB_FORMAT_CALLBACK);
void (*FormatVariant)(DB_DRIVER *, GB_VARIANT_VALUE *, DB_FORMAT_CALLBACK);
int (*IsDebug)(void);
void (*TryAnother)(const char *);
char *(*SubstString)(const char *, int, DB_SUBST_CALLBACK);
char *(*QuoteString)(const char *, int, char);
DB_DATABASE *(*GetCurrentDatabase)();
struct {
void (*Init)(void);
void (*Add)(const char *);
void (*AddLength)(const char *, int);
char *(*Get)(void);
char *(*GetNew)(void);
int (*Length)(void);
}
Query;
struct {
int (*Find)(char **, const char *);
}
StringArray;
}
DB_INTERFACE;
/* Field datatypes */
#define DB_T_SERIAL ((GB_TYPE)-1)
#define DB_T_BLOB ((GB_TYPE)-2)
/* Field Separator Character e.g. Table.field = Table.field */
#define FLD_SEP '.'
#endif /* __MAIN_H */