android - SQLite Query Confusion, Less than Greater than -
i give function day , hour , want fetch column_day1=day , hour in between 2 text-not-null columns column_from1 , column_to1. weird thing if give hour 7, , from1 , to1 contain 6 , 9 respectively, return positive search. if give hour 12 , from1 , to1 containt 11 , 17 respectively search works.
but, when give 7 , from1 , to1 contain 6 , 10 respectively search doesn't work. think it's related 10 being 2 digit , 6 being 1 digit or along lines. below cursor query use please help, , doing wrong?
cursor cursor = database.query(mysqlitehelper.table_comments, allcolumns, mysqlitehelper.column_day1 +" ='" + day+ "' , " +mysqlitehelper.column_from1 + " <=" + hour+ " , " +mysqlitehelper.column_to1+ " >" +hour , null, null, null, null);
edit: should return true when column_from1 contains 6 , column_to1 contains 10.
function writes data sqlite database:
inputstream =getresources().openrawresource(r.raw.ems_data); bufferedinputstream bis = new bufferedinputstream(is); bytearraybuffer baf = new bytearraybuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } byte[] mydata = baf.tobytearray(); string datainstring = new string(mydata); string[] lines = datainstring.split("\n"); (int i=0; i<lines.length; i++){ comment = datasource.createcomment(lines[i]); // adapter.add(comment); }
edit:
the createcomment(); function:
public comment createcomment(string comment) { contentvalues values = new contentvalues(); //parse data in string comment string[] words = comment.split("\\t"); values.put(mysqlitehelper.column_comment, comment); values.put(mysqlitehelper.column_name, words[0]); //adds column "name" values.put(mysqlitehelper.column_contact, words[1]); values.put(mysqlitehelper.column_day1, words[2]); values.put(mysqlitehelper.column_from1, words[3]); values.put(mysqlitehelper.column_to1, words[4]); values.put(mysqlitehelper.column_day2, words[5]); values.put(mysqlitehelper.column_from2, words[6]); values.put(mysqlitehelper.column_to2, words[7]); //expected error above after day2 since can null long insertid = database.insert(mysqlitehelper.table_comments, null, values); cursor cursor = database.query(mysqlitehelper.table_comments, allcolumns, mysqlitehelper.column_id + " = " + insertid, null, null, null, null); cursor.movetofirst(); comment newcomment = cursortocomment(cursor); cursor.close(); return newcomment; }
found answer!
parsing not done beautifully correctly , end of line character \r causing problems sqlite database not recognizing end '9' 9
. added line:
comment = comment.replaceall("(\\r|\\n)", "");
before parsed data \t delimiter , worked!
Comments
Post a Comment