case 0: /* defaults */
host=user=passwd=NULL;
hashed_details_length=5+3;
- hashed_details = (char *) emalloc(hashed_details_length);
+ hashed_details = (char *) emalloc(hashed_details_length+1);
strcpy(hashed_details,"mssql___");
break;
case 1: {
host = Z_STRVAL_PP(yyhost);
user=passwd=NULL;
hashed_details_length = Z_STRLEN_PP(yyhost)+5+3;
- hashed_details = (char *) emalloc(hashed_details_length);
+ hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"mssql_%s__",Z_STRVAL_PP(yyhost));
}
break;
user = Z_STRVAL_PP(yyuser);
passwd=NULL;
hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+5+3;
- hashed_details = (char *) emalloc(hashed_details_length);
+ hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"mssql_%s_%s_",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser));
}
break;
user = Z_STRVAL_PP(yyuser);
passwd = Z_STRVAL_PP(yypasswd);
hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+5+3;
- hashed_details = (char *) emalloc(hashed_details_length);
+ hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"mssql_%s_%s_%s",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser),Z_STRVAL_PP(yypasswd)); /* SAFE */
}
break;
unsigned char *res_buf;
int res_length = dbdatlen(mssql_ptr->link, offset);
- res_buf = (unsigned char *) emalloc(res_length);
+ res_buf = (unsigned char *) emalloc(res_length+1);
bin = ((DBBINARY *)dbdata(mssql_ptr->link, offset));
memcpy(res_buf,bin,res_length);
res_buf[res_length] = '\0';
if (column_type == SQLDATETIM4) res_length += 14;
if (column_type == SQLDATETIME) res_length += 10;
- res_buf = (unsigned char *) emalloc(res_length);
+ res_buf = (unsigned char *) emalloc(res_length+1);
res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR,res_buf,-1);
} else {
dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
res_length = 19;
- res_buf = (unsigned char *) emalloc(res_length);
+ res_buf = (unsigned char *) emalloc(res_length+1);
sprintf(res_buf, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second);
}
unsigned char *res_buf;
int res_length = dbdatlen(mssql_ptr->link, offset);
- res_buf = (unsigned char *) emalloc(res_length);
+ res_buf = (unsigned char *) emalloc(res_length+1);
bin = ((DBBINARY *)dbdata(mssql_ptr->link, offset));
memcpy(res_buf, bin, res_length);
res_buf[res_length] = '\0';
if (column_type == SQLDATETIM4) res_length += 14;
if (column_type == SQLDATETIME) res_length += 10;
- res_buf = (unsigned char *) emalloc(res_length);
+ res_buf = (unsigned char *) emalloc(res_length+1);
res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR, res_buf, -1);
} else {
dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
res_length = 19;
- res_buf = (unsigned char *) emalloc(res_length);
+ res_buf = (unsigned char *) emalloc(res_length+1);
sprintf(res_buf, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second);
}
* 1) Being able to fire up another query without explicitly reading all rows
* 2) Having numrows accessible
*/
- retvalue=dbnextrow(mssql_ptr->link);
-
- if (retvalue==FAIL) {
- RETURN_FALSE;
- }
-
if ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && !dbdataready(mssql_ptr->link)) {
RETURN_TRUE;
}
+ retvalue=dbnextrow(mssql_ptr->link);
+ if (retvalue==FAIL) {
+ RETURN_FALSE;
+ }
+
result = (mssql_result *) emalloc(sizeof(mssql_result));
result->num_fields = num_fields;
result->blocks_initialized = 1;
result->fields = (mssql_field *) emalloc(sizeof(mssql_field)*result->num_fields);
result->num_rows = _mssql_fetch_batch(mssql_ptr, result, retvalue TSRMLS_CC);
}
+ else
+ result->fields = NULL;
ZEND_REGISTER_RESOURCE(return_value, result, le_result);
}