Skip to content

Fix bugs reported in original project #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions lib4d_sql/base64.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2008 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Jim Winstead <[email protected]> |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2008 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Jim Winstead <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id: base64.c,v 1.43.2.2.2.4 2007/12/31 07:20:12 sebastian Exp $ */

/* $Id: base64.c 287670 2009-08-25 08:35:39Z fourd $ */

#include <string.h>
#include <stdlib.h>
@@ -55,13 +56,13 @@ static const short base64_reverse_table[256] = {

/* {{{ php_base64_encode */
//PHPAPI
unsigned char *base64_encode(const unsigned char *str, int length, int *ret_length)
unsigned char *base64_encode(const char *str, size_t length, int *ret_length)
{
const unsigned char *current = str;
const char *current = str;
unsigned char *p;
unsigned char *result;

if ((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) {
if (((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) {
if (ret_length != NULL) {
*ret_length = 0;
}
@@ -137,17 +138,17 @@ void php_base64_init(void)
/* }}} */

//PHPAPI
unsigned char *base64_decode(const unsigned char *str, int length, int *ret_length)
unsigned char *base64_decode(const char *str, size_t length, int *ret_length)
{
return base64_decode_ex(str, length, ret_length, 0);
}

/* {{{ php_base64_decode */
/* as above, but backwards. :) */
//PHPAPI
unsigned char *base64_decode_ex(const unsigned char *str, int length, int *ret_length, int strict)
unsigned char *base64_decode_ex(const char *str, size_t length, int *ret_length, int strict)
{
const unsigned char *current = str;
const char *current = str;
int ch, i = 0, j = 0, k;
/* this sucks for threaded environments */
unsigned char *result;
8 changes: 4 additions & 4 deletions lib4d_sql/base64.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: base64.h,v 1.14.2.1.2.3 2007/12/31 07:20:12 sebastian Exp $ */
/* $Id: base64.h 279540 2009-04-29 08:57:22Z splanquart $ */

#ifndef BASE64_H
#define BASE64_H
@@ -25,11 +25,11 @@
//PHP_FUNCTION(base64_encode);

//PHPAPI extern
unsigned char *base64_encode(const unsigned char *, int, int *);
unsigned char *base64_encode(const char *, size_t, int *);
//PHPAPI extern
unsigned char *base64_decode_ex(const unsigned char *, int, int *, int);
unsigned char *base64_decode_ex(const char *, size_t, int *, int);
//PHPAPI extern
unsigned char *base64_decode(const unsigned char *, int, int *);
unsigned char *base64_decode(const char *, size_t, int *);

#endif /* BASE64_H */

999 changes: 616 additions & 383 deletions lib4d_sql/communication.c
100644 → 100755

Large diffs are not rendered by default.

871 changes: 486 additions & 385 deletions lib4d_sql/fourd.c
100644 → 100755

Large diffs are not rendered by default.

544 changes: 292 additions & 252 deletions lib4d_sql/fourd.h
100644 → 100755

Large diffs are not rendered by default.

162 changes: 96 additions & 66 deletions lib4d_sql/fourd_int.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,68 +1,98 @@
#ifndef __FOURD_INT__
#define __FOURD_INT__ 1
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int Printf(const char* format,...);
int Printferr(const char* format,...);

/*******************/
/* communication.c */
/*******************/
int socket_connect(FOURD *cnx,const char *host,unsigned int port);
void socket_disconnect(FOURD *cnx);
int socket_send(FOURD *cnx,const char*msg);
int socket_send_data(FOURD *cnx,const char*msg,int len);
//int socket_receiv(FOURD *cnx);
int socket_receiv_header(FOURD *cnx,FOURD_RESULT *state);
int socket_receiv_data(FOURD *cnx,FOURD_RESULT *state);
/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/
#ifndef __FOURD_INT__
#define __FOURD_INT__ 1
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int Printf(const char* format,...);
int Printferr(const char* format,...);

/*******************/
/* communication.c */
/*******************/
int socket_connect(FOURD *cnx,const char *host,unsigned int port);
void socket_disconnect(FOURD *cnx);
int socket_send(FOURD *cnx,const char*msg);
int socket_send_data(FOURD *cnx,const char*msg,int len);
//int socket_receiv(FOURD *cnx);
int socket_receiv_header(FOURD *cnx,FOURD_RESULT *state);
int socket_receiv_data(FOURD *cnx,FOURD_RESULT *state);
int socket_receiv_update_count(FOURD *cnx,FOURD_RESULT *state);
int set_sock_blocking(int socketd, int block);
int socket_connect_timeout(FOURD *cnx,const char *host,unsigned int port,unsigned int timeout);
/*******************/
/* fourd_interne.c */
/*******************/
//return 0 for OK et -1 for no readable header and error_code
int login(FOURD *cnx,unsigned short int id_cnx,const char *user,const char*pwd,const char*image_type);
int logout(FOURD *cnx,unsigned short int id_cmd);
int quit(FOURD *cnx,unsigned short int id_cmd);
//return 0 for OK et -1 for no readable header and error_code
int _query(FOURD *cnx,unsigned short int id_cmd,const char *request,FOURD_RESULT *result);
int __fetch_result(FOURD *cnx,unsigned short int id_cmd,int statement_id,int command_index,unsigned int first_row,unsigned int last_row,FOURD_RESULT *result);
int _fetch_result(FOURD_RESULT *res,unsigned short int id_cmd);
int get(const char* msg,const char* section,char *valeur,int max_length);
//FOURD_LONG8 get_status(FOURD* cnx);
//int traite_header_reponse(FOURD* cnx);
int traite_header_response(FOURD_RESULT* cnx);
FOURD_LONG8 _get_status(const char *header,int *status,FOURD_LONG8 *error_code,char *error_string);
int receiv_check(FOURD *cnx,FOURD_RESULT *state);
void _free_data_result(FOURD_RESULT *res);
//clear connection attribut
void _clear_atrr_cnx(FOURD *cnx);
int close_statement(FOURD_RESULT *res,unsigned short int id_cmd);

int _query_param(FOURD *cnx,unsigned short int id_cmd, const char *request,unsigned int nbParam, const FOURD_ELEMENT *param,FOURD_RESULT *result);

/*********************/
/* Memory Allocation */
/*********************/
void *_copy(FOURD_TYPE type,void *org);
char *_serialize(char *data,int *size, FOURD_TYPE type, void *pObj);
void Free(void *p);
void FreeFloat(FOURD_FLOAT *p);
void FreeString(FOURD_STRING *p);
void FreeBlob(FOURD_BLOB *p);
void PrintData(const void *data,unsigned int size);
#ifndef WIN32
void ZeroMemory (void *s, size_t n);
#define WSAGetLastError() errno
#define strtok_s(a,b,c) strtok(a,b)
#define strcpy_s(s,size,cs) strncpy(s,cs,size)
#define strncpy_s(s,ms,cs,size) strncpy(s,cs,size)
int sprintf_s(char *buff,int size,const char* format,...);
int _snprintf_s(char *buff, int size, int count, const char *format,...);
#endif


#endif
int socket_connect_timeout(FOURD *cnx,const char *host,unsigned int port,int timeout);
/*******************/
/* fourd_interne.c */
/*******************/
//return 0 for OK et -1 for no readable header and error_code
int dblogin(FOURD *cnx,unsigned short int id_cnx,const char *user,const char*pwd,const char*image_type);
int dblogout(FOURD *cnx,unsigned short int id_cmd);
int quit(FOURD *cnx,unsigned short int id_cmd);
//return 0 for OK et -1 for no readable header and error_code
int _query(FOURD *cnx,unsigned short int id_cmd,const char *request,FOURD_RESULT *result,const char*image_type, int res_size);
int __fetch_result(FOURD *cnx,unsigned short int id_cmd,int statement_id,int command_index,unsigned int first_row,unsigned int last_row,FOURD_RESULT *result);
int _fetch_result(FOURD_RESULT *res,unsigned short int id_cmd);
int get(const char* msg,const char* section,char *valeur,int max_length);
//FOURD_LONG8 get_status(FOURD* cnx);
//int traite_header_reponse(FOURD* cnx);
int traite_header_response(FOURD_RESULT* cnx);
FOURD_LONG8 _get_status(const char *header,int *status,FOURD_LONG8 *error_code,char *error_string);
int receiv_check(FOURD *cnx,FOURD_RESULT *state);
void _free_data_result(FOURD_RESULT *res);
//clear connection attribut
void _clear_atrr_cnx(FOURD *cnx);
int close_statement(FOURD_RESULT *res,unsigned short int id_cmd);

int _prepare_statement(FOURD *cnx,unsigned short int id_cmd,const char *request);
int _query_param(FOURD *cnx,unsigned short int id_cmd, const char *request,unsigned int nbParam, const FOURD_ELEMENT *param,FOURD_RESULT *result,const char*image_type, int res_size);
int _is_multi_query(const char *request);
int _valid_query(FOURD *cnx,const char *request);
/*********************/
/* Memory Allocation */
/*********************/
void *_copy(FOURD_TYPE type,void *org);
char *_serialize(char *data,unsigned int *size, FOURD_TYPE type, void *pObj);
void Free(void *p);
void FreeFloat(FOURD_FLOAT *p);
void FreeString(FOURD_STRING *p);
void FreeBlob(FOURD_BLOB *p);
void PrintData(const void *data,unsigned int size);
#ifndef WIN32
void ZeroMemory (void *s, size_t n);
#define WSAGetLastError() errno
#define strtok_s(a,b,c) strtok(a,b)
#define strcpy_s(s,size,cs) strncpy(s,cs,size)
#define strncpy_s(s,ms,cs,size) strncpy(s,cs,size)
int sprintf_s(char *buff,size_t size,const char* format,...);
int _snprintf_s(char *buff, size_t size, size_t count, const char *format,...);
#endif


#endif
1,760 changes: 992 additions & 768 deletions lib4d_sql/fourd_interne.c
100644 → 100755

Large diffs are not rendered by default.

39 changes: 34 additions & 5 deletions lib4d_sql/fourd_result.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
#include "fourd.h"
#include "fourd_int.h"
FOURD_LONG8 fourd_num_rows(FOURD_RESULT *result)
{
return result->row_count;
/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/

#include "fourd.h"
#include "fourd_int.h"
FOURD_LONG8 fourd_num_rows(FOURD_RESULT *result)
{
return result->row_count;
}
308 changes: 172 additions & 136 deletions lib4d_sql/fourd_type.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,137 +1,173 @@
#include <stdio.h>
#include <string.h>

extern int Printf(const char* format,...);
extern int Printferr(const char* format,...);
#include "fourd.h"
FOURD_TYPE typeFromString(const char *type)
{
if(strcmp(type,"VK_BOOLEAN")==0)
return VK_BOOLEAN;
if(strcmp(type,"VK_BYTE")==0)
return VK_BYTE;
if(strcmp(type,"VK_WORD")==0)
return VK_WORD;
if(strcmp(type,"VK_LONG")==0)
return VK_LONG;
if(strcmp(type,"VK_LONG8")==0)
return VK_LONG8;
if(strcmp(type,"VK_REAL")==0)
return VK_REAL;
if(strcmp(type,"VK_FLOAT")==0)
return VK_FLOAT;
if(strcmp(type,"VK_TIMESTAMP")==0)
return VK_TIMESTAMP;
if(strcmp(type,"VK_TIME")==0)
return VK_TIMESTAMP;
if(strcmp(type,"VK_DURATION")==0)
return VK_DURATION;
if(strcmp(type,"VK_TEXT")==0)
return VK_STRING;
if(strcmp(type,"VK_STRING")==0)
return VK_STRING;
if(strcmp(type,"VK_BLOB")==0)
return VK_BLOB;
if(strcmp(type,"VK_IMAGE")==0)
return VK_IMAGE;
return VK_UNKNOW;
}
const char* stringFromType(FOURD_TYPE type)
{
switch(type)
{
case VK_BOOLEAN:
return "VK_BOOLEAN";
case VK_BYTE:
return "VK_BYTE";
case VK_WORD:
return "VK_WORD";
case VK_LONG:
return "VK_LONG";
case VK_LONG8:
return "VK_LONG8";
case VK_REAL:
return "VK_REAL";
case VK_FLOAT:
return "VK_FLOAT";
case VK_TIMESTAMP:
return "VK_TIMESTAMP";
case VK_TIME:
return "VK_TIME";
case VK_DURATION:
return "VK_DURATION";
case VK_STRING:
return "VK_STRING";
case VK_BLOB:
return "VK_BLOB";
case VK_IMAGE:
return "VK_IMAGE";
default:
return "VK_UNKNOW";
break;
}
}
/******************************************************************/
/* vk_sizeof */
/******************************************************************/
/* return sizeof type or -1 if varying length or 0 if unknow type */
/******************************************************************/
int vk_sizeof(FOURD_TYPE type)
{
switch(type)
{
case VK_BOOLEAN:
case VK_BYTE:
case VK_WORD:
return 2;
break;
case VK_LONG:
return 4;
break;
case VK_LONG8:
case VK_REAL:
case VK_DURATION:
return 8;
break;
case VK_FLOAT:
//Varying length
return -1;
break;
case VK_TIME:
case VK_TIMESTAMP:
return 8;
break;
case VK_TEXT:
case VK_STRING:
case VK_BLOB:
case VK_IMAGE:
//Varying length
return -1;
break;
}
//error type not found
Printf("Error: Unknow type in vk_sizeof function\n");
return 0;
}

FOURD_RESULT_TYPE resultTypeFromString(const char *type)
{
if(strcmp(type,"Update-Count")==0)
return UPDATE_COUNT;
if(strcmp(type,"Result-Set")==0)
return RESULT_SET;
return UNKNOW;
}
const char* stringFromResultType(FOURD_RESULT_TYPE type)
{
switch(type)
{
case UPDATE_COUNT:
return "Update-Count";
break;
case RESULT_SET:
return "Result-Set";
break;
}
return "Unknow";
/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/

#include <stdio.h>
#include <string.h>

extern int Printf(const char* format,...);
extern int Printferr(const char* format,...);
#include "fourd.h"
FOURD_TYPE typeFromString(const char *type)
{
if(strcmp(type,"VK_BOOLEAN")==0)
return VK_BOOLEAN;
if(strcmp(type,"VK_BYTE")==0)
return VK_BYTE;
if(strcmp(type,"VK_WORD")==0)
return VK_WORD;
if(strcmp(type,"VK_LONG")==0)
return VK_LONG;
if(strcmp(type,"VK_LONG8")==0)
return VK_LONG8;
if(strcmp(type,"VK_REAL")==0)
return VK_REAL;
if(strcmp(type,"VK_FLOAT")==0)
return VK_FLOAT;
if(strcmp(type,"VK_TIMESTAMP")==0)
return VK_TIMESTAMP;
if(strcmp(type,"VK_TIME")==0)
return VK_TIMESTAMP;
if(strcmp(type,"VK_DURATION")==0)
return VK_DURATION;
if(strcmp(type,"VK_TEXT")==0)
return VK_STRING;
if(strcmp(type,"VK_STRING")==0)
return VK_STRING;
if(strcmp(type,"VK_BLOB")==0)
return VK_BLOB;
if(strcmp(type,"VK_IMAGE")==0)
return VK_IMAGE;
return VK_UNKNOW;
}
const char* stringFromType(FOURD_TYPE type)
{
switch(type)
{
case VK_BOOLEAN:
return "VK_BOOLEAN";
case VK_BYTE:
return "VK_BYTE";
case VK_WORD:
return "VK_WORD";
case VK_LONG:
return "VK_LONG";
case VK_LONG8:
return "VK_LONG8";
case VK_REAL:
return "VK_REAL";
case VK_FLOAT:
return "VK_FLOAT";
case VK_TIMESTAMP:
return "VK_TIMESTAMP";
case VK_TIME:
return "VK_TIME";
case VK_DURATION:
return "VK_DURATION";
case VK_STRING:
return "VK_STRING";
case VK_BLOB:
return "VK_BLOB";
case VK_IMAGE:
return "VK_IMAGE";
default:
return "VK_UNKNOW";
break;
}
}
/******************************************************************/
/* vk_sizeof */
/******************************************************************/
/* return sizeof type or -1 if varying length or 0 if unknow type */
/******************************************************************/
int vk_sizeof(FOURD_TYPE type)
{
switch(type)
{
case VK_BOOLEAN:
case VK_BYTE:
case VK_WORD:
return 2;
break;
case VK_LONG:
return 4;
break;
case VK_LONG8:
case VK_REAL:
case VK_DURATION:
return 8;
break;
case VK_FLOAT:
//Varying length
return -1;
break;
case VK_TIME:
case VK_TIMESTAMP:
return 8;
break;
case VK_TEXT:
case VK_STRING:
case VK_BLOB:
case VK_IMAGE:
//Varying length
return -1;
break;
default:
Printf("Error: Unknow type in vk_sizeof function\n");
return 0;
break;
}
//error type not found. Should now be handled by the default switch case
Printf("Error: Unknow type in vk_sizeof function\n");
return 0;
}

FOURD_RESULT_TYPE resultTypeFromString(const char *type)
{
if(strcmp(type,"Update-Count")==0)
return UPDATE_COUNT;
if(strcmp(type,"Result-Set")==0)
return RESULT_SET;
return UNKNOW;
}
const char* stringFromResultType(FOURD_RESULT_TYPE type)
{
switch(type)
{
case UPDATE_COUNT:
return "Update-Count";
break;
case RESULT_SET:
return "Result-Set";
break;
default:
return "Unknown";
break;
}
return "Unknown";
}
144 changes: 86 additions & 58 deletions lib4d_sql/fourd_type.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,59 +1,87 @@
#ifndef __FOURD_TYPE__
#define __FOURD_TYPE__
typedef enum
{
VK_UNKNOW=0,
VK_BOOLEAN,
VK_BYTE,
VK_WORD,
VK_LONG,
VK_LONG8,
VK_REAL,
VK_FLOAT,
VK_TIMESTAMP,
VK_DURATION,
VK_STRING,
VK_BLOB,
VK_IMAGE
}FOURD_TYPE;
/******************************/
/* parse and format FOUR_TYPE */
/******************************/
FOURD_TYPE typeFromString(const char *type);
const char* stringFromType(FOURD_TYPE type);
/******************************************************************/
/* vk_sizeof */
/******************************************************************/
/* return sizeof type or -1 if varying length or 0 if unknow type */
/******************************************************************/
int vk_sizeof(FOURD_TYPE type);

/***************/
/* Result-Type */
/***************/
typedef enum
{
UNKNOW=0,
UPDATE_COUNT,
RESULT_SET
}FOURD_RESULT_TYPE;
FOURD_RESULT_TYPE resultTypeFromString(const char *type);
const char* stringFromResultType(FOURD_RESULT_TYPE type);

/*********************/
/* Structure of VK_* */
/*********************/
typedef short FOURD_BOOLEAN;
typedef short FOURD_BYTE;
typedef short FOURD_WORD;
typedef int FOURD_LONG;
typedef __int64 FOURD_LONG8;
typedef double FOURD_REAL;
typedef struct{int exp;char sign;int data_length;void* data;}FOURD_FLOAT;
typedef struct{short year;char mounth;char day;unsigned int milli;}FOURD_TIMESTAMP;
typedef __int64 FOURD_DURATION;//in milliseconds
typedef struct{int length;unsigned char *data;}FOURD_STRING;
typedef struct{unsigned int length;void *data;}FOURD_BLOB;
//typedef struct{}FOURD_IMAGE;

/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/
#ifndef __FOURD_TYPE__
#define __FOURD_TYPE__
typedef enum
{
VK_UNKNOW=0,
VK_BOOLEAN,
VK_BYTE,
VK_WORD,
VK_LONG,
VK_LONG8,
VK_REAL,
VK_FLOAT,
VK_TIMESTAMP,
VK_DURATION,
VK_STRING,
VK_BLOB,
VK_IMAGE
}FOURD_TYPE;
/******************************/
/* parse and format FOUR_TYPE */
/******************************/
FOURD_TYPE typeFromString(const char *type);
const char* stringFromType(FOURD_TYPE type);
/******************************************************************/
/* vk_sizeof */
/******************************************************************/
/* return sizeof type or -1 if varying length or 0 if unknow type */
/******************************************************************/
int vk_sizeof(FOURD_TYPE type);

/***************/
/* Result-Type */
/***************/
typedef enum
{
UNKNOW=0,
UPDATE_COUNT,
RESULT_SET
}FOURD_RESULT_TYPE;
FOURD_RESULT_TYPE resultTypeFromString(const char *type);
const char* stringFromResultType(FOURD_RESULT_TYPE type);

/*********************/
/* Structure of VK_* */
/*********************/
typedef short FOURD_BOOLEAN;
typedef short FOURD_BYTE;
typedef short FOURD_WORD;
typedef int FOURD_LONG;
typedef __int64 FOURD_LONG8;
typedef double FOURD_REAL;
typedef struct{int exp;char sign;int data_length;void* data;}FOURD_FLOAT;
typedef struct{short year;char mounth;char day;unsigned int milli;}FOURD_TIMESTAMP;
typedef __int64 FOURD_DURATION;//in milliseconds
typedef struct{int length;unsigned char *data;}FOURD_STRING;
typedef struct{unsigned int length;void *data;}FOURD_BLOB;
//typedef struct{}FOURD_IMAGE;

#endif
59 changes: 44 additions & 15 deletions lib4d_sql/sqlstate.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
#include "fourd.h"
const char * fourd_sqlstate(FOURD *cnx)
{
switch(cnx->error_code){
case -10060: return "08001";/* Unable to connect to server => Client unable to establish connection */
case -1: return "01S00";
/*case 1105: return "08004";*/ /* Failed to authenticate. => Server rejected the connection */

case 1101: return "42P01"; /* Failed to execute statement. => Undefined table <= TABLE DOES NOT EXIST */
/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/

#include "fourd.h"
const char * fourd_sqlstate(FOURD *cnx)
{
switch(cnx->error_code){
case -10060: return "08001";/* Unable to connect to server => Client unable to establish connection */
case -1: return "01S00";
/*case 1105: return "08004";*/ /* Failed to authenticate. => Server rejected the connection */

case 1101: return "42P01"; /* Failed to execute statement. => Undefined table <= TABLE DOES NOT EXIST */
case 1102: return "42S22"; /* Column not found <= colonne DOES NOT EXIST*/
case 1103: return "42P01"; /* Undefined table <= TABLE NOT DECLARED IN FROM CLAUSE */
case 1104: return "42702"; /* Ambiguous column <= AMBIGUOUS COLUMN NAME */
case 1105: return "42P09"; /* Ambiguous alias <= TABLE ALIAS SAME AS TABLE NAME */
case 1106: return "42P09"; /* Ambiguous alias <= DUPLICATE TABLE ALIAS */
case 1107: return "42P09"; /* Ambiguous alias <= DUPLICATE TABLE IN FROM CLAUSE */
case 1108: return "HY004"; /* Failed to execute statement. => Invalid SQL data type <= INCOMPATIBLE TYPES */
case 1108: return "HY004"; /* Failed to execute statement. => Invalid SQL data type <= INCOMPATIBLE TYPES */

case 1109: return "HY000"; /* <= INVALID ORDER BY INDEX */
case 1110: return "42P08"; /* Ambiguous parameter <= WRONG AMOUNT OF PARAMETERS */
@@ -51,7 +80,7 @@ const char * fourd_sqlstate(FOURD *cnx)
case 1133: return "21S01"; /* Insert value list does not match column list <= DUPLICATE COLUMN IN INSERT */
case 1134: return "23502"; /* Not null violation <= COLUMN DOES NOT ALLOW NULLS */
case 1135: return "42701"; /* Duplicate column <= DUPLICATE COLUMN IN UPDATE */
case 1136: return "42P07"; /* Duplicate table <= TABLE ALREADY EXISTS */
case 1136: return "42P07"; /* Duplicate table <= TABLE ALREADY EXISTS */

case 1137: return "42701"; /* Duplicate column <= DUPLICATE COLUMN IN CREATE TABLE */
case 1138: return "42701"; /* Duplicate column <= DUPLICATE COLUMN IN COLUMN LIST */
@@ -100,7 +129,7 @@ const char * fourd_sqlstate(FOURD *cnx)
case 1220: return "HY000"; /* <= FAILED TO LOAD RECORD */
case 1221: return "HY000"; /* <= FAILED TO LOCK RECORD FOR WRITING */
case 1222: return "HY000"; /* <= FAILED TO PUT SQL LOCK ON A TABLE */


case 1301: return "42601"; /* Failed to parse statement. => Syntax error */


@@ -178,7 +207,7 @@ const char * fourd_sqlstate(FOURD *cnx)
case 3013: return "HY000"; /* <= BASE64 ENCODING ERROR */
case 3014: return "HY000"; /* <= INVALID HEADER TERMINATOR */


default: return "HY000";
}
case -5001: return "0LP01"; /* driver not support multiquery */
default: return "HY000";
}
}
71 changes: 50 additions & 21 deletions lib4d_sql/utils.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
#include <string.h>
#define isspace(x) (x==' ')
char *strstrip(char *s)
{
size_t size;
char *end;

size = strlen(s);

if (!size)
return s;

end = s + size - 1;
while (end != s && isspace(*end))
end--;
*(end + 1) = '\0';

while (*s && isspace(*s))
s++;

return s;
/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/

#include <string.h>
#define isspace(x) (x==' ')
char *strstrip(char *s)
{
size_t size;
char *end;

size = strlen(s);

if (!size)
return s;

end = s + size - 1;
while (end != s && isspace(*end))
end--;
*(end + 1) = '\0';

while (*s && isspace(*s))
s++;

return s;
}
29 changes: 29 additions & 0 deletions lib4d_sql/utils.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
/*
+----------------------------------------------------------------------+
| lib4D_SQL |
+----------------------------------------------------------------------+
| Copyright (c) 2009 The PHP Group |
+----------------------------------------------------------------------+
| |
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| |
| Its original copy is usable under several licenses and is available |
| through the world-wide-web at the following url: |
| http://freshmeat.net/projects/lib4d_sql |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Contributed by: 4D <php@4d.fr>, http://www.4d.com |
| Alter Way, http://www.alterway.fr |
| Authors: Stephane Planquart <stephane.planquart@o4db.com> |
| Alexandre Morgaut <php@4d.fr> |
+----------------------------------------------------------------------+
*/

char *strstrip(char *s);