Skip to content

Commit 08b788d

Browse files
committed
Bug #20426. Convert SMALLDATETIME correct
1 parent 710b20a commit 08b788d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

ext/mssql/php_mssql.c

+18-4
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,22 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off
822822
DBDATEREC dateinfo;
823823
int res_length = dbdatlen(mssql_ptr->link,offset);
824824

825-
if ((column_type != SQLDATETIME) || MS_SQL_G(datetimeconvert)) {
825+
if ((column_type != SQLDATETIME && column_type != SQLDATETIM4) || MS_SQL_G(datetimeconvert)) {
826826

827827
if (column_type == SQLDATETIM4) res_length += 14;
828828
if (column_type == SQLDATETIME) res_length += 10;
829829

830830
res_buf = (unsigned char *) emalloc(res_length+1);
831831
res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR,res_buf,-1);
832832
} else {
833-
dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
833+
if (column_type == SQLDATETIM4) {
834+
DBDATETIME temp;
835+
836+
dbconvert(NULL, SQLDATETIM4, dbdata(mssql_ptr->link,offset), -1, SQLDATETIME, (LPBYTE) &temp, -1);
837+
dbdatecrack(mssql_ptr->link, &dateinfo, &temp);
838+
} else {
839+
dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
840+
}
834841

835842
res_length = 19;
836843
res_buf = (unsigned char *) emalloc(res_length+1);
@@ -875,7 +882,7 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int
875882
DBDATEREC dateinfo;
876883
int res_length = dbdatlen(mssql_ptr->link,offset);
877884

878-
if ((column_type != SQLDATETIME) || MS_SQL_G(datetimeconvert)) {
885+
if ((column_type != SQLDATETIME && column_type != SQLDATETIM4) || MS_SQL_G(datetimeconvert)) {
879886

880887
if (column_type == SQLDATETIM4) res_length += 14;
881888
if (column_type == SQLDATETIME) res_length += 10;
@@ -884,7 +891,14 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int
884891
res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR, res_buf, -1);
885892

886893
} else {
887-
dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
894+
if (column_type == SQLDATETIM4) {
895+
DBDATETIME temp;
896+
897+
dbconvert(NULL, SQLDATETIM4, dbdata(mssql_ptr->link,offset), -1, SQLDATETIME, (LPBYTE) &temp, -1);
898+
dbdatecrack(mssql_ptr->link, &dateinfo, &temp);
899+
} else {
900+
dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
901+
}
888902

889903
res_length = 19;
890904
res_buf = (unsigned char *) emalloc(res_length+1);

0 commit comments

Comments
 (0)