Sqlite时间段查询中遇到的问题

问题:ide

我要查询DateTime时间其中的一段符合时间要求的数据,好比我要查询‘2019-06-06 16:50:00’至‘2019-06-06 16:59:00’这一段的数据code

开始用这段代码orm

strSql= ("select * from CollectTableRtd where datetime(DateTime)>=datetime('2019-06-06 16:50:00') and datetime(DateTime)<=datetime('2019-06-06 16:59:00')");  是能够查询出来的,而后换下面代码:内存

strSql= ("select * from CollectTableRtd where datetime(DateTime)>=datetime('datetime_strf1') and datetime(DateTime)<=datetime('datetime_strf2')");   ci

其中datetime_strf一、datetime_strf2是从控件读取的选择时间,然而并无正确读取,下面也同样:unicode

strSql= ("select * from CollectTableRtd where datetime(DateTime)>=datetime(datetime_strf1) and datetime(DateTime)<=datetime(datetime_strf2)");   字符串

sprintf(strSql,"select * from CollectTableRtd where datetime(DateTime)>=datetime('%s') and datetime(DateTime)<=datetime('%s')",datetime_strf1.GetBuffer(),datetime_strf2.GetBuffer());string

后来查阅资料得知须要用%S读取,结果并验证正确,附代码以下:it

sprintf(strSql,"select * from CollectTableRtd where datetime(DateTime)>=datetime('%S') and datetime(DateTime)<=datetime('%S')",datetime_strf1.GetBuffer(),datetime_strf2.GetBuffer());io

在这里将%s与%S的区别讲一讲,以下:

请看MSDN:http://msdn.microsoft.com/zh-cn/library/hf4y5e3w(v=vs.90).aspx

的解释。

 

 

s

String

When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached.

S

String

When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte–character string. Characters are printed up to the first null character or until the precision value is reached.

 

使用s时,printf是针对单字节字符的字符串,而wprintf是针对宽字符的

使用S时,正好相反,printf针对宽字符

 

CString中的format与printf相似,在unicode字符集的工程中,使用

CString str1, str2;

str1.format(_T("%S"), str2);

%S专指单字节字符的字符串,而str2为宽字符,类型不匹配,故出现不可预期的错误。

 

若str2为英文字符,如“abcd”,就只能输出a,因str2为宽字符,a有两个字节,值为0x0061,在内存中为61 00,故按单字节输出只能输出61,碰到00,即空字符后认为字符串结束,不会再输出。

若str2为中文字符,中文字符通常会占满两字节,而按单字节字符就会按一个字节一个字节的输出,故会输出乱码。  

相关文章
相关标签/搜索