2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
CResult.c
|
|
|
|
|
2011-03-21 01:04:10 +01:00
|
|
|
(c) 2000-2011 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
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
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
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
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __CRESULT_C
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include "deletemap.h"
|
2009-07-07 11:17:48 +02:00
|
|
|
#include "CField.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "CResultField.h"
|
|
|
|
#include "CResult.h"
|
|
|
|
|
|
|
|
GB_CLASS CLASS_Blob;
|
|
|
|
|
|
|
|
static CBLOB *make_blob(CRESULT *result, int field);
|
2008-01-17 22:39:26 +01:00
|
|
|
static void set_blob(CBLOB *_object, char *data, int length);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
static GB_SUBCOLLECTION_DESC _fields_desc =
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
".ResultFields",
|
|
|
|
(void *)CRESULTFIELD_get,
|
|
|
|
(void *)CRESULTFIELD_exist,
|
|
|
|
(void *)NULL,
|
|
|
|
(void *)CRESULTFIELD_release
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int check_result(CRESULT *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
return (THIS->conn->db.handle == NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_available(CRESULT *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
if (!THIS->available)
|
|
|
|
{
|
|
|
|
GB.Error("Result is not available");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void init_buffer(CRESULT *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->info.nfield == 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Alloc(POINTER(&THIS->buffer), sizeof(GB_VARIANT_VALUE) * THIS->info.nfield);
|
|
|
|
BARRAY_create(&THIS->changed, THIS->info.nfield);
|
2007-12-30 17:41:49 +01:00
|
|
|
BARRAY_clear_all(THIS->changed, THIS->info.nfield);
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
for (i = 0; i < THIS->info.nfield; i++)
|
|
|
|
THIS->buffer[i].type = GB_T_NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void void_buffer(CRESULT *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//fprintf(stderr, "void_buffer\n");
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->info.nfield == 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
for (i = 0; i < THIS->info.nfield; i++)
|
|
|
|
GB.StoreVariant(NULL, &THIS->buffer[i]);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
BARRAY_clear_all(THIS->changed, THIS->info.nfield);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void release_buffer(CRESULT *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->buffer)
|
|
|
|
{
|
|
|
|
void_buffer(THIS);
|
|
|
|
GB.Free(POINTER(&THIS->buffer));
|
|
|
|
BARRAY_delete(&THIS->changed);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool load_buffer(CRESULT *_object, int vpos)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
int i, ind;
|
|
|
|
int pos;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//fprintf(stderr, "load_buffer: %ld -> %d\n", THIS->pos, vpos);
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
/* if THIS->count < 0, that's mean that the driver couldn't determine it */
|
|
|
|
|
|
|
|
DB_CurrentDatabase = &THIS->conn->db;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->count >= 0 && (vpos < 0 || vpos >= THIS->count || THIS->info.nfield == 0))
|
|
|
|
{
|
2007-12-30 17:41:49 +01:00
|
|
|
/* Andrea Bortolan's changes for the ODBC modules*/
|
|
|
|
|
|
|
|
/* ODBC does return the number of rows affected by the query when execute a insert,apdate or delete query,
|
2008-09-09 13:03:47 +02:00
|
|
|
for all others case it returns -1 even if the query was execute without errors */
|
2007-12-30 17:41:49 +01:00
|
|
|
/* Here the check for this case -1 means that the query was executed correctly
|
2008-09-09 13:03:47 +02:00
|
|
|
so get the result. */
|
2007-12-30 17:41:49 +01:00
|
|
|
/* If the pos (the result row) does not exist because pos is > of the rows available than the ODBC module
|
2008-09-09 13:03:47 +02:00
|
|
|
will rise an Error ODBC_END_OF_DATA that must be catched by the application */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (THIS->count == -1)
|
|
|
|
{
|
|
|
|
if (THIS->handle && pos != THIS->pos)
|
|
|
|
{
|
|
|
|
THIS->driver->Result.Fill(THIS->handle, pos, THIS->buffer,(pos > 0) && (pos == (THIS->pos + 1)));
|
|
|
|
}
|
|
|
|
THIS->pos = pos;
|
|
|
|
THIS->available = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* End of Andrea's changes */
|
|
|
|
#endif
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
{
|
2007-12-30 17:41:49 +01:00
|
|
|
THIS->pos = -1;
|
|
|
|
THIS->available = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-09 13:03:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (THIS->handle && vpos != THIS->pos)
|
|
|
|
{
|
|
|
|
pos = DELETE_MAP_virtual_to_real(THIS->dmap, vpos);
|
|
|
|
|
|
|
|
//fprintf(stderr, "Result %p: Loading real %ld\n", THIS, pos);
|
|
|
|
|
|
|
|
void_buffer(THIS);
|
|
|
|
|
|
|
|
THIS->driver->Result.Fill(&THIS->conn->db, THIS->handle, pos, THIS->buffer,
|
|
|
|
(pos > 0) && (pos == (DELETE_MAP_virtual_to_real(THIS->dmap, THIS->pos) + 1)));
|
|
|
|
|
|
|
|
if (THIS->mode == RESULT_EDIT)
|
|
|
|
{
|
|
|
|
q_init();
|
|
|
|
|
|
|
|
for (i = 0; i < THIS->info.nindex; i++)
|
|
|
|
{
|
|
|
|
ind = THIS->info.index[i];
|
|
|
|
if (i > 0) q_add(" AND ");
|
|
|
|
q_add(THIS->info.field[ind].name);
|
|
|
|
if (THIS->buffer[ind].type == GB_T_NULL)
|
|
|
|
q_add(" IS NULL");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
q_add(" = ");
|
|
|
|
DB_FormatVariant(THIS->driver, &THIS->buffer[ind], q_add_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GB.FreeString(&THIS->edit);
|
|
|
|
THIS->edit = q_steal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THIS->pos = vpos;
|
|
|
|
THIS->available = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void reload_buffer(CRESULT *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
int pos = THIS->pos;
|
|
|
|
THIS->pos = -1;
|
|
|
|
load_buffer(THIS, pos);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void table_release(DB_INFO *info)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (info->table)
|
|
|
|
GB.FreeString(&info->table);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (info->field)
|
|
|
|
{
|
|
|
|
for (i = 0; i < info->nfield; i++)
|
2009-07-07 11:17:48 +02:00
|
|
|
CFIELD_free_info(&info->field[i]);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Free(POINTER(&info->field));
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (info->index)
|
|
|
|
GB.Free(POINTER(&info->index));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GB_TYPE get_field_type(CRESULT *_object, int field)
|
|
|
|
{
|
|
|
|
GB_TYPE type;
|
|
|
|
|
|
|
|
if (THIS->info.field)
|
|
|
|
type = THIS->info.field[field].type;
|
|
|
|
else
|
2008-09-09 13:03:47 +02:00
|
|
|
type = THIS->driver->Result.Field.Type(THIS->handle, field);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//fprintf(stderr, "get_field_type: %d -> %ld\n", field, type);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CRESULT *DB_MakeResult(CCONNECTION *conn, int mode, char *table_temp, char *query)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
CRESULT *_object;
|
|
|
|
DB_RESULT res;
|
|
|
|
char *duplicate;
|
|
|
|
char *token;
|
|
|
|
const char *error = NULL;
|
|
|
|
char *arg;
|
|
|
|
char *table;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case RESULT_FIND:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (conn->driver->Exec(&conn->db, query, &res, "Query failed: &1"))
|
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_CREATE:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
res = NULL;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_EDIT:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (conn->driver->Exec(&conn->db, query, &res, "Query failed: &1"))
|
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_DELETE:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
conn->driver->Exec(&conn->db, query, &res, "Query failed: &1");
|
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
_object = GB.New(GB.FindClass("Result"), NULL, NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->conn = conn;
|
|
|
|
GB.Ref(conn);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->driver = conn->driver;
|
|
|
|
THIS->available = FALSE;
|
|
|
|
THIS->mode = mode;
|
|
|
|
THIS->handle = res;
|
|
|
|
THIS->pos = -1;
|
|
|
|
THIS->dmap = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
// table must be copied because it can be a temporary string!
|
2010-06-05 01:48:53 +02:00
|
|
|
table = GB.NewZeroString(table_temp);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case RESULT_FIND:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->driver->Result.Init(THIS->handle, &THIS->info, &THIS->count);
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_CREATE:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->driver->Table.Init(&conn->db, table, &THIS->info))
|
|
|
|
goto ERROR;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->count = 1;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_EDIT:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->driver->Result.Init(THIS->handle, &THIS->info, &THIS->count);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->driver->Table.Init(&conn->db, table, &THIS->info))
|
|
|
|
goto ERROR;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->driver->Table.Index(&conn->db, table, &THIS->info))
|
|
|
|
{
|
|
|
|
error = "Table '&1' has no primary key";
|
|
|
|
arg = table;
|
|
|
|
goto ERROR;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
init_buffer(THIS);
|
|
|
|
load_buffer(THIS, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.FreeString(&table);
|
|
|
|
return THIS;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
ERROR:
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (!error)
|
|
|
|
{
|
2007-12-30 17:41:49 +01:00
|
|
|
if (strchr(table, (int)',') == NULL)
|
|
|
|
{
|
|
|
|
arg = table;
|
|
|
|
if (!THIS->driver->Table.Exist(&conn->db, table))
|
|
|
|
error = "Unknown table: &1";
|
|
|
|
else
|
|
|
|
error = "Cannot read information about table &1";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
duplicate = GB.NewZeroString(table);
|
2007-12-30 17:41:49 +01:00
|
|
|
token = strtok(duplicate,",");
|
|
|
|
do {
|
|
|
|
arg = token;
|
|
|
|
if (!THIS->driver->Table.Exist(&conn->db, token))
|
|
|
|
error = "Unknown table: &1";
|
|
|
|
else
|
|
|
|
error = "Cannot read information about table '&1'";
|
|
|
|
}
|
|
|
|
while ((token = strtok(NULL, ".")) != NULL);
|
|
|
|
GB.FreeString(&duplicate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GB.Free(POINTER(&_object));
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Error(error, arg);
|
|
|
|
GB.FreeString(&table);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_free)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
release_buffer(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->mode != RESULT_CREATE)
|
|
|
|
THIS->driver->Result.Release(THIS->handle, &THIS->info);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->mode != RESULT_FIND)
|
|
|
|
table_release(&THIS->info);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->edit)
|
|
|
|
GB.FreeString(&THIS->edit);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
DELETE_MAP_free(&THIS->dmap);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Unref(POINTER(&THIS->conn));
|
|
|
|
GB.Unref(POINTER(&THIS->fields));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CRESULT_count)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnInteger(THIS->count);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CRESULT_max)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnInteger(THIS->count - 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CRESULT_index)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnInteger(THIS->pos);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CRESULT_available)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnBoolean(THIS->available);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
static void check_blob(CRESULT *_object, int field)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_VARIANT val;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//fprintf(stderr, "check_blob: %d\n", field);
|
|
|
|
|
|
|
|
if (THIS->buffer[field].type == GB_T_NULL)
|
|
|
|
{
|
|
|
|
val.type = GB_T_VARIANT;
|
|
|
|
val.value.type = (GB_TYPE)CLASS_Blob;
|
2009-12-24 03:02:05 +01:00
|
|
|
val.value.value._object = make_blob(THIS, field);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
GB.StoreVariant(&val, &THIS->buffer[field]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_METHOD(CRESULT_get, GB_STRING field)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
int index;
|
|
|
|
GB_TYPE type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (check_available(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
index = CRESULTFIELD_find(THIS, GB.ToZeroString(ARG(field)), TRUE);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
type = get_field_type(THIS, index);
|
|
|
|
|
|
|
|
if (type == DB_T_BLOB)
|
|
|
|
check_blob(THIS, index);
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnPtr(GB_T_VARIANT, &THIS->buffer[index]);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD(CRESULT_put, GB_VARIANT value; GB_STRING field)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
int index;
|
|
|
|
GB_TYPE type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (check_available(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->mode == RESULT_FIND)
|
|
|
|
{
|
|
|
|
GB.Error("Result is read-only");
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
index = CRESULTFIELD_find(THIS, GB.ToZeroString(ARG(field)), TRUE);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
type = get_field_type(THIS, index);
|
|
|
|
|
|
|
|
if (type == DB_T_SERIAL)
|
|
|
|
{
|
|
|
|
//GB.Error("Read-only field");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == DB_T_BLOB)
|
|
|
|
{
|
|
|
|
check_blob(THIS, index);
|
|
|
|
|
|
|
|
if (VARG(value).type == (GB_TYPE)CLASS_Blob)
|
|
|
|
{
|
2009-12-24 03:02:05 +01:00
|
|
|
CBLOB *src = VARG(value).value._object;
|
|
|
|
set_blob((CBLOB *)THIS->buffer[index].value._object, src->data, src->length);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GB_STRING *str = (GB_STRING *)(void *)ARG(value);
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (GB.Conv((GB_VALUE *)(void *)ARG(value), GB_T_STRING))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-12-24 03:02:05 +01:00
|
|
|
set_blob((CBLOB *)THIS->buffer[index].value._object, str->value.addr + str->value.start, str->value.len);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BARRAY_set(THIS->changed, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (VARG(value).type != GB_T_NULL && VARG(value).type != type)
|
|
|
|
/*{
|
|
|
|
GB.Error("Type mismatch");
|
|
|
|
return;
|
|
|
|
}*/
|
|
|
|
{
|
|
|
|
if (GB.Conv((GB_VALUE *)(void *)ARG(value), THIS->info.field[index].type))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Conv((GB_VALUE *)(void *)ARG(value), GB_T_VARIANT);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.StoreVariant(ARG(value), &THIS->buffer[index]);
|
2007-12-30 17:41:49 +01:00
|
|
|
BARRAY_set(THIS->changed, index);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
BEGIN_METHOD(CRESULT_copy, GB_OBJECT result)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
CRESULT *result = (CRESULT *)VARG(result);
|
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (THIS->mode == RESULT_FIND)
|
|
|
|
{
|
|
|
|
GB.Error("Result is read-only");
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
for (index = 0; index <
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
index = find_field(THIS, GB.ToZeroString(ARG(field)));
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (VARG(value).type != GB_T_NULL && VARG(value).type != THIS->info.types[index])
|
|
|
|
/*{
|
|
|
|
GB.Error("Type mismatch");
|
|
|
|
return;
|
|
|
|
}*/
|
|
|
|
{
|
|
|
|
if (GB.Conv((GB_VALUE *)ARG(value), THIS->info.types[index]))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Conv((GB_VALUE *)ARG(value), GB_T_VARIANT);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.StoreVariant(ARG(value), &THIS->buffer[index]);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_move_first)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnBoolean(load_buffer(THIS, 0));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_move_last)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnBoolean(load_buffer(THIS, THIS->count - 1));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_move_previous)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnBoolean(load_buffer(THIS, THIS->pos - 1));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_move_next)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnBoolean(load_buffer(THIS, THIS->pos + 1));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD(CRESULT_move_to, GB_INTEGER pos)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnBoolean(load_buffer(THIS, VARG(pos)));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_next)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
int *pos = (int *)GB.GetEnum();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (!load_buffer(THIS, *pos))
|
|
|
|
(*pos)++;
|
|
|
|
else
|
|
|
|
GB.StopEnum();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CRESULT_update)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
int i;
|
|
|
|
bool comma;
|
|
|
|
DB_INFO *info = &THIS->info;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (check_available(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
DB_CurrentDatabase = &THIS->conn->db;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_init();
|
|
|
|
|
|
|
|
switch(THIS->mode)
|
|
|
|
{
|
|
|
|
case RESULT_CREATE:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add("INSERT INTO ");
|
2009-11-28 02:22:00 +01:00
|
|
|
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table));
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add(" ( ");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
comma = FALSE;
|
|
|
|
for (i = 0; i < info->nfield; i++)
|
|
|
|
{
|
|
|
|
if (THIS->buffer[i].type == GB_T_NULL)
|
|
|
|
continue;
|
|
|
|
if (!BARRAY_test(THIS->changed, i))
|
|
|
|
continue;
|
|
|
|
if (comma) q_add(", ");
|
|
|
|
q_add(THIS->driver->GetQuote());
|
|
|
|
q_add(info->field[i].name);
|
|
|
|
q_add(THIS->driver->GetQuote());
|
|
|
|
comma = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!comma)
|
|
|
|
{
|
|
|
|
q_add(THIS->driver->GetQuote());
|
|
|
|
q_add(info->field[0].name);
|
|
|
|
q_add(THIS->driver->GetQuote());
|
|
|
|
}
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add(" ) VALUES ( ");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
comma = FALSE;
|
|
|
|
for (i = 0; i < info->nfield; i++)
|
|
|
|
{
|
|
|
|
if (THIS->buffer[i].type == GB_T_NULL)
|
|
|
|
continue;
|
|
|
|
if (!BARRAY_test(THIS->changed, i))
|
|
|
|
continue;
|
|
|
|
if (comma) q_add(", ");
|
|
|
|
DB_FormatVariant(THIS->driver, &THIS->buffer[i], q_add_length);
|
|
|
|
comma = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!comma)
|
|
|
|
{
|
|
|
|
DB_FormatVariant(THIS->driver, &THIS->buffer[0], q_add_length);
|
|
|
|
}
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add(" )");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (!THIS->driver->Exec(&THIS->conn->db, q_get(), NULL, "Cannot create record: &1"))
|
|
|
|
void_buffer(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_EDIT:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add("UPDATE ");
|
2009-11-28 02:22:00 +01:00
|
|
|
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table));
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add(" SET ");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
comma = FALSE;
|
|
|
|
for (i = 0; i < info->nfield; i++)
|
|
|
|
{
|
2007-12-30 17:41:49 +01:00
|
|
|
if (!BARRAY_test(THIS->changed, i))
|
|
|
|
continue;
|
2008-09-09 13:03:47 +02:00
|
|
|
if (comma) q_add(", ");
|
|
|
|
q_add(THIS->driver->GetQuote());
|
|
|
|
q_add(THIS->info.field[i].name);
|
|
|
|
q_add(THIS->driver->GetQuote());
|
|
|
|
q_add(" = ");
|
|
|
|
DB_FormatVariant(THIS->driver, &THIS->buffer[i], q_add_length);
|
|
|
|
comma = TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add(" WHERE ");
|
|
|
|
q_add(THIS->edit);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->driver->Exec(&THIS->conn->db, q_get(), NULL, "Cannot modify record: &1");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
default:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Error("Result is read-only");
|
|
|
|
break;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
BARRAY_clear_all(THIS->changed, THIS->info.nfield);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_METHOD(CRESULT_delete, GB_BOOLEAN keep)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
DB_INFO *info = &THIS->info;
|
|
|
|
int *pos;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
if (check_available(THIS))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_init();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
switch(THIS->mode)
|
|
|
|
{
|
|
|
|
case RESULT_CREATE:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
void_buffer(THIS);
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
case RESULT_EDIT:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add("DELETE FROM ");
|
2009-11-28 02:22:00 +01:00
|
|
|
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table));
|
2008-09-09 13:03:47 +02:00
|
|
|
q_add(" WHERE ");
|
|
|
|
q_add(THIS->edit);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
THIS->driver->Exec(&THIS->conn->db, q_get(), NULL, "Cannot delete record: &1");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!VARGOPT(keep, FALSE))
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
DELETE_MAP_add(&THIS->dmap, THIS->pos);
|
|
|
|
THIS->count--;
|
|
|
|
reload_buffer(THIS);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
GB.ListEnum(THIS);
|
|
|
|
while (!GB.NextEnum())
|
|
|
|
{
|
2008-01-17 22:39:26 +01:00
|
|
|
pos = (int *)GB.GetEnum();
|
2007-12-30 17:41:49 +01:00
|
|
|
if (*pos > THIS->pos)
|
|
|
|
(*pos)--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
default:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.Error("Result is read-only");
|
|
|
|
break;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CRESULT_fields)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.SubCollection.New(&THIS->fields, &_fields_desc, THIS);
|
|
|
|
GB.ReturnObject(THIS->fields);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CRESULT_connection)
|
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB.ReturnObject(THIS->conn);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
GB_DESC CResultDesc[] =
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_DECLARE("Result", sizeof(CRESULT)), GB_NOT_CREATABLE(),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_HOOK_CHECK(check_result),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_METHOD("_free", NULL, CRESULT_free, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_PROPERTY_READ("Count", "i", CRESULT_count),
|
|
|
|
GB_PROPERTY_READ("Length", "i", CRESULT_count),
|
|
|
|
GB_PROPERTY_READ("Available", "b", CRESULT_available),
|
|
|
|
GB_PROPERTY_READ("Index", "i", CRESULT_index),
|
|
|
|
GB_PROPERTY_READ("Max", "i", CRESULT_max),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_METHOD("_get", "v", CRESULT_get, "(Field)s"),
|
|
|
|
GB_METHOD("_put", NULL, CRESULT_put, "(Value)v(Field)s"),
|
|
|
|
GB_METHOD("_next", NULL, CRESULT_next, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_METHOD("MoveFirst", "b", CRESULT_move_first, NULL),
|
|
|
|
GB_METHOD("MoveLast", "b", CRESULT_move_last, NULL),
|
|
|
|
GB_METHOD("MovePrevious", "b", CRESULT_move_previous, NULL),
|
|
|
|
GB_METHOD("MoveNext", "b", CRESULT_move_next, NULL),
|
|
|
|
GB_METHOD("MoveTo", "b", CRESULT_move_to, "(Index)i"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_METHOD("Update", NULL, CRESULT_update, NULL),
|
|
|
|
GB_METHOD("Delete", NULL, CRESULT_delete, "[(Keep)b]"),
|
2009-07-17 03:29:39 +02:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_PROPERTY_READ("Fields", ".ResultFields", CRESULT_fields),
|
|
|
|
GB_PROPERTY_READ("Connection", "Connection", CRESULT_connection),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Blob *******************************************************************/
|
|
|
|
|
|
|
|
/*static int check_blob(CBLOB *_object)
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
return check_result(BLOB->result) || (BLOB->result->pos != BLOB->pos);
|
2007-12-30 17:41:49 +01:00
|
|
|
}*/
|
|
|
|
|
|
|
|
static CBLOB *make_blob(CRESULT *result, int field)
|
|
|
|
{
|
|
|
|
CBLOB *_object;
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
_object = GB.New(CLASS_Blob, NULL, NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
//BLOB->result = result;
|
|
|
|
//GB.Ref(result);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//BLOB->field = field;
|
|
|
|
//BLOB->pos = result->pos;
|
|
|
|
BLOB->data = NULL;
|
|
|
|
BLOB->length = 0;
|
|
|
|
|
|
|
|
if (result->handle && result->pos >= 0)
|
|
|
|
result->driver->Result.Blob(result->handle, result->pos, field, BLOB);
|
|
|
|
|
|
|
|
//fprintf(stderr, "make_blob: %d (%ld) -> %p\n", field, BLOB->length, BLOB);
|
|
|
|
|
|
|
|
//GB.UnrefKeep(POINTER(&_object), FALSE);
|
|
|
|
return BLOB;
|
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
static void set_blob(CBLOB *_object, char *data, int length)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
//fprintf(stderr, "set_blob: %p %ld\n", BLOB, length);
|
|
|
|
|
|
|
|
if (!BLOB->constant)
|
|
|
|
GB.FreeString((char **)&BLOB->data);
|
|
|
|
|
|
|
|
if (data && length)
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
*((char **)&BLOB->data) = GB.NewString(data, length);
|
2007-12-30 17:41:49 +01:00
|
|
|
BLOB->constant = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLOB->length = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CBLOB_init)
|
|
|
|
|
|
|
|
CLASS_Blob = GB.FindClass("Blob");
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_METHOD_VOID(CBLOB_free)
|
|
|
|
|
|
|
|
//GB.Unref(POINTER(&BLOB->result));
|
|
|
|
set_blob(BLOB, NULL, 0);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
/*BEGIN_PROPERTY(CBLOB_result)
|
|
|
|
|
|
|
|
GB.ReturnObject(BLOB->result);
|
|
|
|
|
|
|
|
END_PROPERTY*/
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CBLOB_data)
|
|
|
|
|
|
|
|
if (READ_PROPERTY)
|
|
|
|
{
|
|
|
|
if (BLOB->length)
|
|
|
|
GB.ReturnConstString(BLOB->data, BLOB->length);
|
|
|
|
else
|
|
|
|
GB.ReturnNull();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_blob(BLOB, PSTRING(), PLENGTH());
|
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CBLOB_length)
|
|
|
|
|
|
|
|
GB.ReturnInteger(BLOB->length);
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
|
|
|
|
GB_DESC CBlobDesc[] =
|
|
|
|
{
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_DECLARE("Blob", sizeof(CBLOB)), GB_NOT_CREATABLE(),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
//GB_HOOK_CHECK(check_blob),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_STATIC_METHOD("_init", NULL, CBLOB_init, NULL),
|
|
|
|
GB_METHOD("_free", NULL, CBLOB_free, NULL),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
//GB_PROPERTY_READ("Result", "Result", CBLOB_result),
|
|
|
|
GB_PROPERTY("Data", "s", CBLOB_data),
|
|
|
|
GB_PROPERTY_READ("Length", "i", CBLOB_length),
|
|
|
|
//GB_METHOD("_unknown", "v", CBLOB_unknown, "v"),
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-09 13:03:47 +02:00
|
|
|
GB_END_DECLARE
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|