@@ -90,7 +90,7 @@ DDB_GetEntity <- function(xxdb_type) {
9090 } else if (xxdb_type == 1 ) {
9191 # Scalar Logical
9292 if (ReturnScalarNA()) {
93- result <- NA
93+ result <- as.logical( NA )
9494 } else {
9595 result <- ReturnScalarBool()
9696 }
@@ -100,7 +100,7 @@ DDB_GetEntity <- function(xxdb_type) {
100100 } else if (xxdb_type == 2 ) {
101101 # Scalar Integer
102102 if (ReturnScalarNA()) {
103- result <- NA
103+ result <- as.integer( NA )
104104 } else {
105105 result <- ReturnScalarInt()
106106 }
@@ -110,7 +110,7 @@ DDB_GetEntity <- function(xxdb_type) {
110110 } else if (xxdb_type == 3 ) {
111111 # Scalar Numeric
112112 if (ReturnScalarNA()) {
113- result <- NA
113+ result <- as.numeric( NA )
114114 } else {
115115 result <- ReturnScalarDouble()
116116 }
@@ -120,7 +120,7 @@ DDB_GetEntity <- function(xxdb_type) {
120120 } else if (xxdb_type == 4 ) {
121121 # Scalar Character
122122 if (ReturnScalarNA()) {
123- result <- NA
123+ result <- as.character( NA )
124124 } else {
125125 result <- ReturnScalarString()
126126 }
@@ -130,7 +130,7 @@ DDB_GetEntity <- function(xxdb_type) {
130130 } else if (xxdb_type == 14 ) {
131131 # Scalar Date
132132 if (ReturnScalarNA()) {
133- result <- NA
133+ result <- as.Date( NA )
134134 } else {
135135 result <- ReturnScalarDate()
136136 }
@@ -140,7 +140,7 @@ DDB_GetEntity <- function(xxdb_type) {
140140 } else if (xxdb_type == 15 ) {
141141 # Scalar DateTime
142142 if (ReturnScalarNA()) {
143- result <- NA
143+ result <- as.POSIXct( NA )
144144 } else {
145145 result <- ReturnScalarTime()
146146 }
@@ -157,6 +157,7 @@ DDB_GetEntity <- function(xxdb_type) {
157157 } else if (xxdb_type == 6 ) {
158158 # Integer Vector
159159 result <- ReturnVectorInt()
160+ result <- DDB_SetReceiveVectorNA(result , ReturnVectorNAIndex())
160161 Clear()
161162 return (result )
162163
@@ -199,6 +200,7 @@ DDB_GetEntity <- function(xxdb_type) {
199200 } else if (xxdb_type == 10 ) {
200201 # Integer Matrix
201202 result <- ReturnMatrixInt()
203+ result <- DDB_SetReceiveVectorNA(result , ReturnMatrixNAIndex())
202204 result <- DDB_ReceiveMatrixLable(result )
203205 Clear()
204206 return (result )
@@ -282,7 +284,7 @@ DDB_GetEntity <- function(xxdb_type) {
282284 }
283285
284286 result <- result [,- 1 ]
285- if (class(result ) != " data.frame" ){
287+ if (class(result )[ 1 ] != " data.frame" ){
286288 # if the result only contains one column, then must convert it to dataFrame Explicitly, or it will be a vecor
287289 result = data.frame (result )
288290 }
@@ -294,8 +296,12 @@ DDB_GetEntity <- function(xxdb_type) {
294296 # AnyVector => list
295297 anyVector <- list ()
296298 anytypelist <- ReturnAnyVectorTypelist()
297-
298- for (i in 1 : length(anytypelist )) {
299+ len = length(anytypelist )
300+ if (len == 0 ){
301+ Clear()
302+ return (anyVector )
303+ }
304+ for (i in 1 : len ) {
299305 if (anytypelist [i ] == 0 ) {
300306 # void
301307 result <- NA
@@ -487,22 +493,20 @@ DDB_GetEntity <- function(xxdb_type) {
487493# call different C++ functions to upload
488494# different types of R objects.
489495DDB_UploadScalar <- function (scl ) {
490- if (is.na(scl ) || is.nan(scl )) {
496+ if (is.integer(scl )) {
497+ UploadScalarInt(scl )
498+ }
499+ else if (is.numeric(scl )) {
500+ UploadScalarDouble(scl )
501+ }
502+ else if (is.na(scl )) {
491503
492504 UploadScalarNULL()
493505
494506 } else if (is.logical(scl )) {
495507
496508 UploadScalarBool(scl )
497509
498- } else if (is.integer(scl )) {
499-
500- UploadScalarInt(scl )
501-
502- } else if (is.numeric(scl )) {
503-
504- UploadScalarDouble(scl )
505-
506510 } else if (is.character(scl )) {
507511
508512 UploadScalarString(scl )
@@ -572,7 +576,7 @@ DDB_UploadVector <- function(vec) {
572576 NAIndex <- DDB_SetUploadVectorNA(vec )
573577 UploadVectorDouble(vec , NAIndex )
574578
575- } else if (is.character(vec ) || class (vec ) == " factor " ) {
579+ } else if (is.character(vec ) || is.factor (vec )) {
576580
577581 NAIndex <- DDB_SetUploadVectorNA(vec )
578582 UploadVectorString(vec , NAIndex )
@@ -583,7 +587,7 @@ DDB_UploadVector <- function(vec) {
583587 NAIndex <- DDB_SetUploadVectorNA(vec )
584588 UploadVectorDateTime(vec , NAIndex )
585589
586- } else if (class (vec ) == " Date" ) {
590+ } else if (inherits (vec , " Date" ) ) {
587591 NAIndex <- DDB_SetUploadVectorNA(vec )
588592 UploadVectorDate(vec , NAIndex )
589593
@@ -615,7 +619,7 @@ DDB_UploadMatrixLable <- function(mtx) {
615619 DDB_UploadVector(rownames(mtx ))
616620 }
617621 if (is.null(colnames(mtx )) == FALSE ) {
618- DDB_UploadVector(rownames (mtx ))
622+ DDB_UploadVector(colnames (mtx ))
619623 }
620624}
621625
@@ -683,13 +687,13 @@ DDB_UploadObjectCheck <- function(args) {
683687
684688 } else if (is.vector(args [[i ]]) && length(args [[i ]]) == 1 ) {
685689
686- } else if (class(args [[i ]]) == " Date" && length(args [[i ]]) == 1 ) {
690+ } else if (class(args [[i ]])[ 1 ] == " Date" && length(args [[i ]]) == 1 ) {
687691
688- } else if (class(args [[i ]]) == " Date" && length(args [[i ]]) > 1 ) {
692+ } else if (class(args [[i ]])[ 1 ] == " Date" && length(args [[i ]]) > 1 ) {
689693
690- } else if (class(args [[i ]]) == c( " POSIXct" , " POSIXt " ) && length(args [[i ]]) == 1 ) {
694+ } else if (class(args [[i ]])[ 1 ] == " POSIXct" && length(args [[i ]]) == 1 ) {
691695
692- } else if (class(args [[i ]]) == c( " POSIXct" , " POSIXt " ) && length(args [[i ]]) > 1 ) {
696+ } else if (class(args [[i ]])[ 1 ] == " POSIXct" && length(args [[i ]]) > 1 ) {
693697
694698 } else {
695699 print(" Data form not support yet." )
@@ -715,9 +719,20 @@ DDB_UploadEntity <- function(args) {
715719 } else if (is.vector(args [[i ]]) && length(args [[i ]]) == 1 ) {
716720 DDB_UploadScalar(args [[i ]])
717721 } else if (length(class(args [[i ]])) == 2 && class(args [[i ]])[1 ] == " POSIXct" ) {
718- DDB_UploadVectorDateTime(args [[i ]])
722+ if (length(args [[i ]]) == 1 ){
723+ DDB_UploadScalarDateTime(args [[i ]])
724+ }
725+ else {
726+ DDB_UploadVectorDateTime(args [[i ]])
727+ }
728+
719729 } else if (class(args [[i ]]) == " Date" ) {
720- DDB_UploadVectorDate(args [[i ]])
730+ if (length(args [[i ]]) == 1 ){
731+ DDB_UploadScalarDate(args [[i ]])
732+ }
733+ else {
734+ DDB_UploadVectorDate(args [[i ]])
735+ }
721736 } else {
722737 print(" Data form not support yet" )
723738 Clear()
0 commit comments