Android SQL查询语法

时间:2016-06-16 15:54:14

标签: android sqlite android-sqlite

我使用这个java类来创建数据库:

public class DBhelper extends SQLiteOpenHelper {

private static final String DB_NAME = "grades.db";
private static final int DB_VERSION = 1;
public static final String TABELLA_RICETTE = "TabellaRicette";
public static final String COL_ID="ColonnaId";
public static final String COL_NOME="ColonnaNome";
public static final String COL_TIPO = "ColonnaTipo";
public static final String COL_IMMAGINE = "ColonnaImmagine";
public static final String COL_ATTRIBUTI="ColonnaAttributi";
public static final String COL_INGREDIENTI = "ColonnaIngredienti";
public static final String COL_DIFFICOLTA="ColonnaDifficolta";
public static final String COL_DESCRIZIONE="ColonnaDescrizione";

public DBhelper(Context context){
    super(context, DB_NAME, null, DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String sql_tab = "create table " + TABELLA_RICETTE + "( " +
            COL_ID + " integer primary key autoincrement, " +
            COL_NOME + " text not null, " +
            COL_TIPO + " text not null, " +
            COL_IMMAGINE + " text not null, " +
            COL_ATTRIBUTI + " text not null, " +
            COL_INGREDIENTI + " text not null, " +
            COL_DIFFICOLTA + " text not null, " +
            COL_DESCRIZIONE + " text not null " +
            ");";
    db.execSQL(sql_tab);
}

@Override
   public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

我使用此函数获取数据库中的所有信息:

public Cursor get_all() {
    return getWritableDatabase().query(TABELLA_RICETTE, null, null, null, null, null, null);
}

现在,我将提出一个更具体的查询,选择String s1COL_TIPOString s2 COL_DIFFICOLTA中具有特定public Cursor get_something(String s1,String s2) { String whereClause="COL_TIPO=? AND COL_DIFFICOLTA=?"; String[] whereArgs=new String[] {s1,s2}; return getWritableDatabase().query(TABELLA_RICETTE,null,null,whereClause,whereArgs,null,null,null); } 的所有元素。

我试着写一些东西,但也许我的语法也错了。

你能帮我解决这个问题吗?

img = Image.new( 'RGB', (2000,2000), "black") # create a new black image
pixels = img.load() # create the pixel map

for i in range(img.size[0]):    # for every pixel:
    for j in range(img.size[1]):
      #do some stuff that requires i and j as parameter

1 个答案:

答案 0 :(得分:1)

COL_TIPO不是列的名称,而是包含列名称的符号的名称。

您必须将符号的值放入SQL字符串中:

String whereClause = COL_TIPO+"=? AND "+COL_DIFFICOLTA+"=?";