My query is
dbAdapter.selectRecordsFromDB("OmniaDB",new String[]{"imsi","type","msg","length","dt_gen","dt_send"},"type"+"="+"call"+"AND"+"dt_send"+"="+"null",null,null,null,"dt_gen");
Thrown exception is
android.database.sqlite.SQLiteException: no such column: callANDdt_send: , while compiling: SELECT imsi, type, msg, length, dt_gen, dt_send FROM OmniaDB WHERE type=callANDdt_send=null ORDER BY dt_gen
You're missing a ton of spaces in "type"+"="+"call"+"AND"+"dt_send"+"="+"null", should be "type='call' AND dt_send=null". Why are you even using concatenation when it should be a giant string? Anyway, there might be something else wrong after you fix that, though, since I have no clue what your data looks like.
"type"+"="+"call"+"AND"+"dt_send"+"="+"null"
None of this makes sense. Getting rid of the unnecessary concatenations leaves
"type = call AND dt_send = null"
which is invalid SQL. You're not quoting properly for the string call, and you can't compare NULL for equality with anything (including NULL).
This is more likely what you should be using:
"type = 'call' AND dt_send IS NULL"
There are probably other problems with the mess you posted, but this should solve at least one of them. (For instance, type may be a reserved word in SQLite; I'm not sure.)
Related
I trying to connect my Android application to a database on remote host.
I want to use the records of the DB, but there's a problem when i try to do this:
if(buffer.toString()=="OPEN")
{
button_signal.setText("OPEN");
}
else
{
button_signal.setText("CLOSE");
}
I have checked buffer.toString() using Logs, and it is equal to "OPEN", but the button_signal's text is printed "CLOSE". Why? Can you help me?
It might have some invisible characters or some letters might be in different case, so please try this:
buffer.toString().trim().equalsIgnoreCase("OPEN");
You can't compare String with the "==" Operator in Java. A String is an Object.
Try this buffer.toString().equals("OPEN");
EDIT:
Even better is if you compare it like this: "OPEN".equals(buffer.toString())
Because it won't throw an exception if buffer is null.
Some of my users report that on their Samsung devices (GT-N7000 & SGH-I777) a query I make in my app for the CallLog.Calls displays also text messages.
I've created a dump of their CallLog ContentProvider, and it seems to have extra fields not mentioned in the Android API, and not returned on any of our test devices.
Specifically, looking through the dump, there's a field called logtype, which seems to equal 100 for calls, and 300 for text messages.
Having searching online for this field, I didn't find any official documentation for this field's values, but I came across lots of other possible values for this field mainly via crash stack traces, which reveal underlining queries by the ContentProvider:
logtype=300 OR logtype=200
logtype=100 OR logtype=500 OR logtype=800 OR logtype=900 OR
logtype=1000
So I assume that 300/200 are used for text messages, and 100/500/800/900/1000 are used for calls, but I'm not sure, since I haven't seen 500/800/900/1000 being used on the reporting users' devices.
Can someone shed some light for the possible values of logtype, and their meaning?
Hello If you will check callLog.Calls columns you will find messageid field which says that this is message for samsung phones.
So if you just want to get the list of calls without messages simply do :
int messageIdIndex=cursor.getColumnIndex("messageid");
while (cursor.moveToNext())
{
if(messageIdIndex>=0)
messageID=cursor.getLong(messageIdIndex);
if(messageID<=0)
{
//do whatever you need with calls log data
}
}
cursor.close();
I've managed to tentatively solve it by querying CallLog.Calls for the column logtype, if an exception is thrown, I query normally, otherwise, I query with selection of (logtype=100 OR logtype=500)
This seems to be working for my reporting users, but I'm still not sure if it covers all bases, since there are many possible values for logtype for which I don't know the meaning.
If anyone has a better answer, please add it.
When i was debugging a sgs2 device i have found this. may be useful for someone.
SELECT number, name, type, date, duration FROM logs WHERE (
logs.logtype=100 OR
logs.logtype=110 OR
logs.logtype=900 OR
logs.logtype=500 OR
logs.logtype=800 OR
logs.logtype=120 OR
logs.logtype=510 OR
logs.logtype=1000 OR
(logs.logtype=200 AND number NOT IN (SELECT number FROM logs WHERE number LIKE '%#%')) OR logs.logtype=300)
AND ((type != 4)) AND (logtype=100 OR logtype=500)))
ORDER BY date DESC
So far, we have found Samsung devices using the value 1150, 100 or 1000 for the 'logtype' field in the Calls content provider.
I cannot confirm if any of the other values mentioned here are used.
I FINALLY have the map and points(arrays) working for my app. Quick question: I have a fatal exception with substring(), a "stringIndexOutOfBoundException"
In general, what is that referring to?
An I going past the end of a string using substring()?
Thanks,
testing.substring(1,2);
(I want to parse each character to find specific characters)
I wouldn't use substring() for grabbing 1-length strings (which is just a single character), but rather charAt(int) for specific positions. If you need to go over all characters in the string, you're probably better off with by converting the whole thing to a char[] first (using toCharArray()) and iterate over that.
Yes, you're going past the end of your strings bounds generally.
The Java API even tells you so...
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.
You should get used to using the API. It tells you what exceptions a method throws and why.
Try printing the Strings length and value before attempting substring. That'll help you see the problem.
For example...
String testing = "Hello StackOverflow";
System.out.println("Length of testing = " + testing.length);
System.out.println("Value of testing = " + testing);
testing.substring(1,2);
Like stated in the official doc here:
public String substring(int beginIndex)
Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.
Throws: IndexOutOfBoundsException - if beginIndex is negative or
larger than the length of this String object.
i want to insert default value in database table
and i am using and put text string below:
INSERT INTO song_text VALUES(1,'Tell me girl, what's it gonna be I
want you, baby do you want me You got me going insane, I'm losing my
mind Is your love true, or am I wasting my time',1);
but it is giving exception:
12-02 14:11:37.860: ERROR/Database(568): Failure 1 (near "s": syntax
error) on 0x247be8 when preparing 'INSERT INTO song_text
VALUES(2,'Tell me girl, what's it gonna be
please give any solution..
thanks
You have to escape the apostrophes:
INSERT INTO song_text VALUES(1,'Tell me girl, what\'s it gonna be I want you, baby do you want me You got me going insane, I\'m losing my mind Is your love true, or am I wasting my time',1);
You should escape characters for your String, since for what's, it understands you have finished your String. Thus you should use: what\'s.
To be generic, you can use a method to replace all ' to \'. For example you may use:
private String convertString(String x) {
return x = x.replace("'","\'");
}
Hope this helps!
I see that AbstractWindowedCursor has methods to check the type of a column. This is a great convenience! But when I look at the CursorWindow class, I see that the documentation for isBlob() says:
Checks if a field contains either a blob or is null.
So, does this mean that if I run this check on, say, a String column that contains a NULL value, will it return true? If so, this means I can't rely on that method as a guaranteed type check.
Checks if a field contains either a blob or is null.
So, does this mean that if I run this check on, say, a String column that contains a NULL value, will it return true?
I haven't tried it myself but I suspect the answer is 'yes' (either that or there's a typo in the docs).
However, if you run isNull() first and that returns 'true' then you know that it isn't going to be possible to tell what the 'column' type is anyway (the isXxxx methods check the type of data the 'field' contains not the 'column' type).
But if you run isNull() first and it returns 'false' then run isBlob(), if it returns true the field contains a blob.