Jump to content
DNPereira

[Resolvido] [SQLite Android]Dúvidas Query

Recommended Posts

DNPereira

Não estou a prceber onde está o erro


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Sqlite{
final static String KEY_NEW= "_id";
final static String KEY_Buy = "pack_buy";
final static String KEY_NAME= "pack_name";
private final static String DATABASE_NAME = "Purshased";
private final static String DATABASE_TABLE = "PackNames";
private final static int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
public static class DbHelper extends SQLiteOpenHelper{

 public DbHelper(Context context){
  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  // TODO Auto-generated constructor stub
 }
 public void onCreate(SQLiteDatabase db){
  // TODO Auto-generated constructor stub
  db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
 KEY_NEW + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
 KEY_Buy + " TEXT NOT NULL, " +
 KEY_NAME + " TEXT NOT NULL);"
  );

 }
 @Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  // TODO Auto-generated method stub
  db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
  onCreate(db);
 }
}
public Sqlite(Context c){
 ourContext = c;
}
public Sqlite open()throws SQLException{
 ourHelper = new DbHelper(ourContext);
 ourDatabase = ourHelper.getWritableDatabase();
 return this;
}
public void close(){
 ourHelper.close();
}
public long createEntry(String bUY) {
 // TODO Auto-generated method stub
 ContentValues cv = new ContentValues();
 cv.put(KEY_NAME, bUY);
 return ourDatabase.insert(DATABASE_TABLE, KEY_NEW, cv);
}
public String getData() {
 // TODO Auto-generated method stub
 String[] namePack = new String [] {KEY_NAME};
 Cursor cs = ourDatabase.rawQuery("SELECT " + DATABASE_TABLE + " (" +
   KEY_NAME +");", namePack);
  if (cs.moveToFirst()) {
   String a = cs.getString(cs.getColumnIndex("pack_name"));
   cs.close();
   return a;
  }
  cs.close();
  return "";
}
}

ERRO

04-12 15:19:32.599: E/AndroidRuntime(6374): FATAL EXCEPTION: main
04-12 15:19:32.599: E/AndroidRuntime(6374): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2012, result=-1, data=null} to activity {com.test.pot/com.test.LayoutOne}: android.database.sqlite.SQLiteException: no such column: pack_name: , while compiling: SELECT PackNames (pack_name);

Share this post


Link to post
Share on other sites
KTachyon

SELECT PackNames (pack_name);

Isto não me parece uma query bem feita.

Mas está lá escrito:

SQLiteException: no such column: pack_name: , while compiling: SELECT PackNames (pack_name);

Edited by KTachyon

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.