通过使用Android的sqlite的语句转换八进制数字符串值? [英] Convert octal number to string value by using sqlite statements in Android?

查看:216
本文介绍了通过使用Android的sqlite的语句转换八进制数字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想插入特殊字符值到我的SQLite表。对于我已经使用下面的查询,包含八进制值。

I'm trying to insert a special character values into my sqlite table. For that i have used following query, that contains octal values.

 "INSERT INTO \"manufacturers\" VALUES(NULL,NULL,NULL,'1970-01-01 00:00:00','1970-01-01 00:00:00','35','A Priorite\\047');"

当我展示它没有转化为相应的字符串值的名称,它会显示插入为(A Priorite \\ 047)相同的八进制值;

when i displaying the names it doesn't converted to corresponding string value, it displays the same octal value inserted as (A Priorite\047);

现在我需要一个建议,通过使用SQLite语句八进制值转换为字符串或字符。

Now i need an suggestion to convert the octal value to string or char by using sqlite statements.

我知道我们可以很容易地通过使用Java code获得它,但我的要求是通过使用SQLite语句来做到这一点。这里的最后一个值是名称字段是包含\\ 047的八进制值(如字符串')​​。

I know we can easily obtain it by using java code but my requirement is to do it by use of sqlite statements. Here the last value is the name field which is contains the octal value of \047(as string ').

我也试过十进制值转换为char,它工作正常。就我而言,如果我八进制值转换为十进制值,那么我可以很容易地转换成char。但我不能八进制转换为十进制。

I've also tried to convert the decimal value to char, it works fine. In my case, if i convert the octal value to decimal value then i can easily convert to char. but i can't convert octal to decimal.

请注意:我有成千上万的记录,所以不能手动特殊字符插入到表的每一行。而且我不应该手动插入值。

Note: I'm having thousands of record, so can't manually insert the special characters into each row of table. And I'm not supposed to insert the values manually.

在此先感谢。任何帮助将是AP preciated。

Thanks in Advance. Any help would be appreciated.

推荐答案

SQLite没有八进制转义。

SQLite does not have octal escapes.

在Android中,你应该只使用参数插入字符串:

In Android, you should just use parameters to insert strings:

String sillyDate = "1970-01-01 00:00:00";
String someNumberAsString = "35";
String name = "A Priorite\047";
db.execSQL("INSERT INTO \"manufacturers\" VALUES(NULL,NULL,NULL,?,?,?,?)",
           new Object[] { sillyDate, sillyDate, someNumberAsString, name });

如果你真的想这样做在SQL中,你必须使用一个十六进制一滴文字和将其转换成文本:

If you really want to do this in SQL, you have to use a hexadecimal blob literal and convert that to text:

"INSERT INTO \"manufacturers\" VALUES(NULL,NULL,NULL,'1970-01-01 00:00:00',"+
"'1970-01-01 00:00:00','35','A Priorite' || x'27');"

请注意,在SQL中,字符串内的报价可以通过将加倍进行转义:

Please note that in SQL, quotes inside strings can be escaped by doubling them:

"INSERT INTO \"manufacturers\" VALUES(NULL,NULL,NULL,'1970-01-01 00:00:00',"+
"'1970-01-01 00:00:00','35','A Priorite''');"

这篇关于通过使用Android的sqlite的语句转换八进制数字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆