From 522b847720a4c3414acbff55369f7be7dc47b2a8 Mon Sep 17 00:00:00 2001
From: ghzhang <zhangguohong@lnxall.com>
Date: Fri, 1 Sep 2023 18:16:19 +0800
Subject: [PATCH] 123

---
 .../ua_history_data_backend_sqlite.c          | 50 +++++++++----------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/plugins/historydata/ua_history_data_backend_sqlite.c b/plugins/historydata/ua_history_data_backend_sqlite.c
index d0d0299..023cf4e 100755
--- a/plugins/historydata/ua_history_data_backend_sqlite.c
+++ b/plugins/historydata/ua_history_data_backend_sqlite.c
@@ -13,7 +13,7 @@
 #include <string.h>
 #include <sqlite3.h>
 
-static char* str_replace_chr(char *line)
+static void str_replace_chr(char *line)
 {
     for(int i = 0; line[i] != '\0';i++)
     {
@@ -100,7 +100,7 @@ getDateTimeMatch_backend_sqlite(UA_Server *server,
 	char sql[512] = {0};
 	char buff[128] = {0};
 	memcpy(buff,nodeId->identifier.string.data,nodeId->identifier.string.length);
-	sprintf(sql,"select count(*) from 'variable' where name = '%s' and time <= %llu",buff,(uint64_t)timestamp);
+	sprintf(sql,"select count(*) from 'variable' where name = '%s' and time <= %" PRId64"",buff,(uint64_t)timestamp);
 	sqlite3_get_table( db , sql , &azResult , &nrow , &ncolumn , &zErrMsg );
 	if(zErrMsg )
 	{
@@ -119,8 +119,8 @@ getDateTimeMatch_backend_sqlite(UA_Server *server,
 	sqlite3_free_table(azResult);
 	sqlite3_free(zErrMsg);
 
-    if ((strategy == MATCH_EQUAL
-         || strategy == MATCH_EQUAL_OR_AFTER
+    if ((strategy == MATCH_EQUAL\
+         || strategy == MATCH_EQUAL_OR_AFTER\
          || strategy == MATCH_EQUAL_OR_BEFORE))
 		if(rowcount == 0) return 0;
 		return (size_t)rowcount-1;
@@ -198,7 +198,7 @@ static char* GetDataValueToStr(const UA_Variant *data)
 	else if(data->type == &UA_TYPES[UA_TYPES_UINT64])
 	{				
 		uint64_t temp1 = *(UA_UInt64*)data->data;
-		sprintf(result,"%llu",temp1);
+		sprintf(result,"%" PRId64"",temp1);
 	}
 	else if(data->type == &UA_TYPES[UA_TYPES_STRING])
 	{				
@@ -300,7 +300,7 @@ serverSetHistoryData_backend_sqlite(UA_Server *server,
 	char buff[128] = {0};
 	memcpy(buff,nodeId->identifier.string.data,nodeId->identifier.string.length);
 	str_replace_chr(buff);
-	sprintf(sql,"INSERT INTO '%s' VALUES(NULL,%d,'%s',%llu)",buff,GetDataTypeToInt(&value->value),result,(uint64_t)timestamp);
+	sprintf(sql,"INSERT INTO '%s' VALUES(NULL,%d,'%s',%" PRId64")",buff,GetDataTypeToInt(&value->value),result,(uint64_t)timestamp);
 	char *zErrMsg =NULL;
     sqlite3_exec(db,sql,NULL,NULL,&zErrMsg);
 	if(zErrMsg )
@@ -460,7 +460,7 @@ getDataValues_backend_sqlite(UA_Server *server,
 		UA_Variant_init(&result[i].value);
 		printf("time:%s\n",azResult[i*3 + 5]);
 		UA_DateTime timestamp = (UA_DateTime)strtoull(azResult[i*3 + 5],NULL,10);
-		//printf("timestamp:%llu\n",timestamp);
+		//printf("timestamp:%" PRId64"\n",timestamp);
 		switch(atoi(azResult[i*3 +3]))
 		{
 			case UA_TYPES_BOOLEAN:
@@ -525,7 +525,7 @@ getDataValues_backend_sqlite(UA_Server *server,
 				ua_result.data = (UA_Byte *)malloc(ua_result.length+1);
 				strcpy((char*)ua_result.data, azResult[i*3 +4]);
 				UA_Variant_setScalarCopy(&result[i].value, &ua_result, &UA_TYPES[UA_TYPES_STRING]);
-				UA_String_deleteMembers(&ua_result);
+				UA_String_clear(&ua_result);
 				break;
 			}
 		}
@@ -585,7 +585,7 @@ getDataValue_backend_sqlite(UA_Server *server,
 	UA_Variant_init(&result->value);
 	//printf("time:%s\n",azResult[5]);
 	UA_DateTime timestamp = (UA_DateTime)strtoull(azResult[5],NULL,10);
-	//printf("timestamp:%llu\n",timestamp);
+	//printf("timestamp:%" PRId64"\n",timestamp);
 	switch(atoi(azResult[3]))
 	{
 		case UA_TYPES_BOOLEAN:
@@ -650,7 +650,7 @@ getDataValue_backend_sqlite(UA_Server *server,
 			ua_result.data = (UA_Byte *)malloc(ua_result.length+1);
 			strcpy((char*)ua_result.data, azResult[4]);
 			UA_Variant_setScalarCopy(&result->value, &ua_result, &UA_TYPES[UA_TYPES_STRING]);
-			UA_String_deleteMembers(&ua_result);
+			UA_String_clear(&ua_result);
 			break;
 		}
 	}
@@ -741,7 +741,7 @@ static UA_StatusCode getHistoryData_backend_sqlite(UA_Server *server,
                   UA_ByteString *outContinuationPoint,
                   UA_HistoryData *result)
 {
-//	printf("start:%llu end:%llu maxSizePerResponse:%d numValuesPerNode:%u \n",start,end,(int)maxSizePerResponse,numValuesPerNode);
+//	printf("start:%" PRId64" end:%" PRId64" maxSizePerResponse:%d numValuesPerNode:%u \n",start,end,(int)maxSizePerResponse,numValuesPerNode);
 
     size_t skip = 0;
     if (continuationPoint->length > 0) {
@@ -775,7 +775,7 @@ static UA_StatusCode getHistoryData_backend_sqlite(UA_Server *server,
 	memcpy(buff,nodeId->identifier.string.data,nodeId->identifier.string.length);
 	str_replace_chr(buff);
 	char sqlCount[512] = {0};
-	int maxSize = maxSizePerResponse ;
+	size_t maxSize = maxSizePerResponse ;
 	// if(numValuesPerNode > 0 && maxSizePerResponse > numValuesPerNode)
 	// {
 	// 	maxSize = numValuesPerNode ;
@@ -785,34 +785,34 @@ static UA_StatusCode getHistoryData_backend_sqlite(UA_Server *server,
 	{
 		if(start < end)
 		{
-			sprintf(sql,"select datatype,result,time from '%s' where  time >= %llu and time <=%llu order by time limit %d offset %d",buff,start,end,maxSize,(int)skip);
-			sprintf(sqlCount,"select count(*) from '%s' where  time >= %llu and time <=%llu",buff,start,end);
+			sprintf(sql,"select datatype,result,time from '%s' where  time >= %" PRId64" and time <=%" PRId64" order by time limit %d offset %d",buff,start,end,maxSize,(int)skip);
+			sprintf(sqlCount,"select count(*) from '%s' where  time >= %" PRId64" and time <=%" PRId64"",buff,start,end);
 		}
 		else if(end == 0)
 		{
-			sprintf(sql,"select datatype,result,time from '%s' where  time >= %llu order by time limit %d  offset %d",buff,start,maxSize,(int)skip);
-			sprintf(sqlCount,"select count(*) from '%s' where  time >= %llu",buff,start);
+			sprintf(sql,"select datatype,result,time from '%s' where  time >= %" PRId64" order by time limit %d  offset %d",buff,start,maxSize,(int)skip);
+			sprintf(sqlCount,"select count(*) from '%s' where  time >= %" PRId64"",buff,start);
 		}
 		else 
 		{
-			sprintf(sql,"select datatype,result,time from '%s' where  time >= %llu and time <=%llu order by time limit %d offset %d",buff,end,start,maxSize,(int)skip);
-			sprintf(sqlCount,"select count(*) from '%s' where  time >= %llu and time <=%llu",buff,end,start);
+			sprintf(sql,"select datatype,result,time from '%s' where  time >= %" PRId64" and time <=%" PRId64" order by time limit %d offset %d",buff,end,start,maxSize,(int)skip);
+			sprintf(sqlCount,"select count(*) from '%s' where  time >= %" PRId64" and time <=%" PRId64"",buff,end,start);
 		}
 	} else {
 		if(start < end)
 		{
-			sprintf(sql,"select datatype,result,time from '%s' where  time > %llu and time <%llu order by time limit %d offset %d",buff,start,end,maxSize,(int)skip);
-			sprintf(sqlCount,"select count(*) from '%s' where time > %llu and time <%llu",buff,start,end);
+			sprintf(sql,"select datatype,result,time from '%s' where  time > %" PRId64" and time <%" PRId64" order by time limit %d offset %d",buff,start,end,maxSize,(int)skip);
+			sprintf(sqlCount,"select count(*) from '%s' where time > %" PRId64" and time <%" PRId64"",buff,start,end);
 		}
 		else if(end == 0)
 		{
-			sprintf(sql,"select datatype,result,time from '%s' where  time > %llu order by time limit %d offset %d",buff,start,maxSize,(int)skip);
-			sprintf(sqlCount,"select count(*) from '%s' where  time > %llu",buff,start);
+			sprintf(sql,"select datatype,result,time from '%s' where  time > %" PRId64" order by time limit %d offset %d",buff,start,maxSize,(int)skip);
+			sprintf(sqlCount,"select count(*) from '%s' where  time > %" PRId64"",buff,start);
 		}
 		else 
 		{
-			sprintf(sql,"select datatype,result,time from '%s' where time > %llu and time <%llu order by time limit %d offset %d",buff,end,start,maxSize,(int)skip);
-			sprintf(sqlCount,"select count(*) from '%s' where time > %llu and time <%llu",buff,end,start);
+			sprintf(sql,"select datatype,result,time from '%s' where time > %" PRId64" and time <%" PRId64" order by time limit %d offset %d",buff,end,start,maxSize,(int)skip);
+			sprintf(sqlCount,"select count(*) from '%s' where time > %" PRId64" and time <%" PRId64"",buff,end,start);
 		}
 	}
 	sqlite3_get_table( db , sqlCount , &azResult , &nrow , &ncolumn , &zErrMsg );
@@ -922,7 +922,7 @@ static UA_StatusCode getHistoryData_backend_sqlite(UA_Server *server,
 				ua_result.data = (UA_Byte *)malloc(ua_result.length+1);
 				strcpy((char*)ua_result.data, azResult[i*3 +4]);
 				UA_Variant_setScalarCopy(&resultValue.value, &ua_result, &UA_TYPES[UA_TYPES_STRING]);
-				UA_String_deleteMembers(&ua_result);
+				UA_String_clear(&ua_result);
 				break;
 			}
 		}
-- 
2.17.1

