Skip to content

Commit e5a18d6

Browse files
committed
implement typemap for getTimeMillis(DateTime $dt)
1 parent 9e0f78a commit e5a18d6

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

src/TimestampUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ namespace griddb {
2525
}
2626

2727
/**
28-
* Convert from Python timestamp to GridDB timestamp
28+
* Convert from PHP DateTime to GridDB timestamp
2929
*/
30-
int64_t TimestampUtils::get_time_millis(double timestamp){
31-
return int64_t(timestamp * 1000);
30+
int64_t TimestampUtils::get_time_millis(int64_t timestamp){
31+
return timestamp;
3232
}
3333

3434
} /* namespace griddb */

src/TimestampUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TimestampUtils {
2929
public:
3030
TimestampUtils();
3131
~TimestampUtils();
32-
static int64_t get_time_millis(double timestamp);
32+
static int64_t get_time_millis(int64_t timestamp);
3333
};
3434

3535
} /* namespace griddb */

src/gstype_php.i

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@
4040
%attribute(griddb::ExpirationInfo, int, divisionCount, get_division_count, set_division_count);
4141

4242
// rename all method to camel cases
43-
%rename(getErrorMessage) griddb::GSException::get_message;
4443
%rename("%(lowercamelcase)s", %$isfunction) "";
4544

45+
// "getMessage" is a default final method of Exception class in PHP. So convert name into getErrorMessage
46+
%rename(getErrorMessage) griddb::GSException::get_message;
47+
48+
// "default" is a PHP keyword. So convert name into DEFAULT_TYPE
49+
%rename(DEFAULT_TYPE) griddb::IndexType::DEFAULT;
50+
4651
/*
4752
* ignore unnecessary functions
4853
*/
@@ -531,12 +536,13 @@
531536
}
532537

533538
/**
534-
* Typemaps for put_row() function
535-
*/
539+
* Typemaps for RowSet::update() and Container::put() function
540+
* The argument "GSRow *row" is not used in the function body, it only for the purpose of typemap matching pattern
541+
* The actual input data is store in class member and can be get by function getGSRowPtr()
542+
*/
536543
%typemap(in, fragment = "convertToFieldWithType") (GSRow *row)
537544
(HashTable *arr, HashPosition pos, zval* data) {
538-
$1 = NULL;
539-
const int size = 60;
545+
const int SIZE = 60;
540546
if(Z_TYPE_P(&$input) != IS_ARRAY) {
541547
SWIG_PHP_Error(E_ERROR, "Expected an array as input");
542548
}
@@ -556,7 +562,7 @@
556562
zend_hash_move_forward_ex(arr, &pos)) {
557563
GSType type = typeList[pos];
558564
if (!(convertToFieldWithType(tmpRow, pos, data, type))) {
559-
char gsType[size];
565+
char gsType[SIZE];
560566
sprintf(gsType, "Invalid value for column %d, type should be : %d", pos, type);
561567
SWIG_PHP_Error(E_ERROR, gsType);
562568
}
@@ -569,6 +575,7 @@
569575
*/
570576
%fragment("convertToRowKeyFieldWithType", "header") {
571577
static bool convertToRowKeyFieldWithType(griddb::Field &field, zval* value, GSType type) {
578+
bool vbool;
572579
field.type = type;
573580

574581
if (Z_TYPE_P(value) == IS_NULL) {
@@ -603,7 +610,10 @@ static bool convertToRowKeyFieldWithType(griddb::Field &field, zval* value, GSTy
603610
field.value.asLong = Z_LVAL_P(value);
604611
break;
605612
case (GS_TYPE_TIMESTAMP):
606-
return convertZvalValueToGSTimestamp(value, &field.value.asTimestamp);
613+
vbool = convertZvalValueToGSTimestamp(value, &field.value.asTimestamp);
614+
if (!vbool) {
615+
return false;
616+
}
607617
break;
608618
default:
609619
//Not support for now
@@ -749,8 +759,8 @@ static bool getRowFields(GSRow* row, int columnCount,
749759
*/
750760
%fragment("convertTimestampToObject", "header") {
751761
static void convertTimestampToObject(GSTimestamp* timestamp, zval* dateTime) {
752-
const int size = 60;
753-
char timeStr[size];
762+
const int SIZE = 60;
763+
char timeStr[SIZE];
754764
zval functionNameZval;
755765
zval formatStringZval;
756766
zval formattedTimePhp;
@@ -790,7 +800,7 @@ static void convertTimestampToObject(GSTimestamp* timestamp, zval* dateTime) {
790800
bool retVal;
791801
int errorColumn;
792802
GSType errorType;
793-
const int size = 60;
803+
const int SIZE = 60;
794804

795805
// Get row pointer
796806
GSRow* row = arg1->getGSRowPtr();
@@ -803,7 +813,7 @@ static void convertTimestampToObject(GSTimestamp* timestamp, zval* dateTime) {
803813
return_value);
804814

805815
if (retVal == false) {
806-
char errorMsg[size];
816+
char errorMsg[SIZE];
807817
sprintf(errorMsg, "Can't get data for field %d with type %d", errorColumn, errorType);
808818
SWIG_PHP_Error(E_ERROR, errorMsg);
809819
}
@@ -827,7 +837,7 @@ static void convertTimestampToObject(GSTimestamp* timestamp, zval* dateTime) {
827837
%typemap(argout, fragment = "getRowFields") (GSRowSetType* type, bool* hasNextRow,
828838
griddb::QueryAnalysisEntry** queryAnalysis, griddb::AggregationResult** aggResult) {
829839

830-
const int size = 60;
840+
const int SIZE = 60;
831841
switch (*$1) {
832842
case (GS_ROW_SET_CONTAINER_ROWS): {
833843
bool retVal;
@@ -842,7 +852,7 @@ static void convertTimestampToObject(GSTimestamp* timestamp, zval* dateTime) {
842852
arg1->getGSTypeList(),
843853
&errorColumn, &errorType, return_value);
844854
if (retVal == false) {
845-
char errorMsg[size];
855+
char errorMsg[SIZE];
846856
sprintf(errorMsg, "Can't get data for field %d with type%d", errorColumn, errorType);
847857
SWIG_PHP_Error(E_ERROR, errorMsg);
848858
}
@@ -890,4 +900,16 @@ static void convertTimestampToObject(GSTimestamp* timestamp, zval* dateTime) {
890900
}
891901
}
892902

903+
/*
904+
* Typemap for TimestampUtils::get_time_millis: convert DateTime object from target language to timestamp with millisecond in C++ layer
905+
*/
906+
%typemap(in, fragement = "convertZvalValueToGSTimestamp") (int64_t timestamp){
907+
bool vbool;
908+
GSTimestamp timestampValue;
909+
vbool = convertZvalValueToGSTimestamp(&$input, &timestampValue);
910+
if(!vbool){
911+
SWIG_PHP_Error(E_ERROR, "Expected a DateTime object as input");
912+
}
913+
$1 = timestampValue;
914+
}
893915

0 commit comments

Comments
 (0)