RLuck
RLuck

Reputation: 93

Error with SQL database

I'm working on a problem and I've been having quite a problem. I get the following error:

03-26 20:34:27.000: E/SQLiteLog(8930): (1) near "INTEGER": syntax error
03-26 20:34:27.002: E/DatabaseUtils(8930): Writing exception to parcel
03-26 20:34:27.002: E/DatabaseUtils(8930): android.database.sqlite.SQLiteException: near    
"INTEGER": syntax error (code 1): , while compiling: SELECT * FROM story_table WHERE TITLE  
LIKE ?  ORDER BY nullLOGIN_ID INTEGER ,STORY_ID INTEGER ,TITLE TEXT ,BODY TEXT ,AUDIO_LINK 
TEXT ,VIDEO_LINK TEXT ,IMAGE_NAME TEXT ,IMAGE_LINK TEXT ,TAGS TEXT ,CREATION_TIME INTEGER 
,STORY_TIME INTEGER ,LATITUDE REAL ,LONGITUDE REAL

Here's what I got for my code. Could someone please help me out with that part. I'm not sure what exactly I'm doing there.

public Cursor query(final String table, final String[] projection,
        final String selection, final String[] selectionArgs,
        final String sortOrder) {
return db.query(table, projection, selection, selectionArgs, null, null, sortOrder 
            + Story_LoginId + " INTEGER ," 
            + Story_StoryId + " INTEGER ," 
            + Story_Title + " TEXT ," 
            + Story_Body + " TEXT ," 
            + Story_AudioLink + " TEXT ," 
            + Story_VideoLink + " TEXT ," 
            + Story_ImageName + " TEXT ," 
            + Story_ImageMetaData + " TEXT ," 
            + Story_Tags + " TEXT ," 
            + Story_CreationTime + " INTEGER ," 
            + Story_StoryTime + " INTEGER ," 
            + Story_Latitude + " REAL ," 
            + Story_Longitude + " REAL  ");

}

Upvotes: 0

Views: 123

Answers (3)

Jorgesys
Jorgesys

Reputation: 126563

according to the logCat you have a problem here "ORDER BY nullLOGIN_ID INTEGER", Select clause don´t need data types.

if you only need a select from a table, this is an example:

return db.query(table, projection, selection, selectionArgs, null, null, sortOrder);

More info: SQLiteDatabase.query method

Upvotes: 1

Amadas
Amadas

Reputation: 703

Your log show why this get error.

SELECT * FROM story_table WHERE TITLE LIKE ?  ORDER BY nullLOGIN_ID INTEGER ,STORY_ID INTEGER ,TITLE TEXT ,BODY TEXT ,AUDIO_LINK TEXT ,VIDEO_LINK TEXT ,IMAGE_NAME TEXT ,IMAGE_LINK TEXT ,TAGS TEXT ,CREATION_TIME INTEGER ,STORY_TIME INTEGER ,LATITUDE REAL ,LONGITUDE REAL  

Select query not need datatype.
datatype need for create table.
You must change your query string.

SELECT * FROM story_table WHERE TITLE LIKE ? ORDER BY nullLOGIN_ID, STORY_ID ... 

Upvotes: 2

SoulTrain
SoulTrain

Reputation: 1904

You would need to cast Columns like Story_LoginId, Story_StoryId, Story_CreationTime into Text first before concatenation them to literal values like INTEGER or REAL.

Upvotes: 0

Related Questions