Skip to content

Instantly share code, notes, and snippets.

@realdm
Created March 30, 2015 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save realdm/7acc6f5db1817a8f461a to your computer and use it in GitHub Desktop.
Save realdm/7acc6f5db1817a8f461a to your computer and use it in GitHub Desktop.
package maputo.gdg.listaeadapters.data;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by Mac on 3/30/2015.
*/
public class WeatherOpenHelper extends SQLiteOpenHelper {
public static final String NOME_DA_BD="sunshine_db";
private static final int VERSAO_DB=1;
public WeatherOpenHelper(Context context) {
super(context, NOME_DA_BD, null, VERSAO_DB);
}
public static interface Tabelas
{
String TBL_LOCALIZACAO="localizacao";
String TBL_TEMPERATURA="temperatura";
}
private static final String CRIAR_TABELA_LOC = "CREATE TABLE "+Tabelas.TBL_LOCALIZACAO+" ("+
WeatherContract.Localizacao.LOC_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
WeatherContract.Localizacao.ZIP_CODE+" INTEGER NOT NULL, "+
WeatherContract.Localizacao.NOME_CIDADE+" TEXT NOT NULL );";
private static final String CRIAR_TABELA_TEMP="CREATE TABLE "+Tabelas.TBL_TEMPERATURA+" ("+
WeatherContract.ColunasPrevisao.PREV_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
WeatherContract.ColunasPrevisao.MIN+" DOUBLE NOT NULL, "+
WeatherContract.ColunasPrevisao.MAX+" DOUBLE NOT NULL, "+
WeatherContract.ColunasPrevisao.ID_LOC+" INTEGER NOT NULL, "+
WeatherContract.ColunasPrevisao.PREV_DESC+" TEXT NOT NULL,"+
"FOREIGN KEY ("+ WeatherContract.ColunasPrevisao.ID_LOC+") REFERENCES "+
Tabelas.TBL_LOCALIZACAO+" ("+ WeatherContract.ColunasLocalizacao.LOC_ID+"));";
@Override
public void onCreate(SQLiteDatabase db) {
//criar tabela de localizacao
db.execSQL(CRIAR_TABELA_LOC);
db.execSQL(CRIAR_TABELA_TEMP);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment