CREACIÓN DE BASES DE DATOS
CREACIÓN DE BASES DE DATOS
Esto se realiza a través de la clase DbHelper, esto permite la creación de la base de datos a través de la ejecución de los comandos SQL:
package com.example.clinicamatasanos.Database; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.renderscript.Sampler; import androidx.annotation.Nullable; import java.util.Queue; public class DbHelper extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 5; private static final String DATABASE_NOMBRE = "clinica_Matasanos.db"; protected static final String TABLA_USUARIO = "Usuarios"; protected static final String TABLA_CITAS = "Citas"; protected static final String TABLA_CONSULTORIO = "Consultorios"; protected static final String TABLA_DATOS_MEDICO = "Datos_medico"; private static final String TABLA_SOLICITUD_CITAS = "Solicitud_Citas"; public DbHelper(@Nullable Context context) { super(context, DATABASE_NOMBRE, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL("CREATE TABLE " + TABLA_USUARIO + "(" + "cedula TEXT PRIMARY KEY," + "nombre TEXT NOT NULL," + "fecha_nacimiento TEXT NOT NULL," + "celular TEXT NOT NULL," + "correo TEXT)"); sqLiteDatabase.execSQL("CREATE TABLE " + TABLA_CONSULTORIO + "(" + "codigo_consultorio INTEGER PRIMARY KEY AUTOINCREMENT," + "ubicacion TEXT NOT NULL," + "Especialidad TEXT NOT NULL)"); sqLiteDatabase.execSQL("CREATE TABLE " + TABLA_DATOS_MEDICO + "(" + "cedula_med TEXT PRIMARY KEY," + "nombre_med TEXT NOT NULL," + "Hora_entrada TEXT NOT NULL," + "Hora_salida TEXT NOT NULL)"); sqLiteDatabase.execSQL("CREATE TABLE " + TABLA_CITAS + "(" + "codigo_cita INTEGER PRIMARY KEY AUTOINCREMENT, " + "cedula TEXT NOT NULL," + "fecha_cita TEXT NOT NULL," + "hora_cita TEXT NOT NULL," + "cedula_med TEXT NOT NULL, " + "codigo_consultorio INTEGER NOT NULL," + "fecha_creacion_cita TEXT NOT NULL, " + "FOREIGN KEY(cedula_med) REFERENCES Datos_medico(cedula_med)," + "FOREIGN KEY(cedula) REFERENCES Usuarios(cedula)," + "FOREIGN KEY(codigo_consultorio) REFERENCES Consultorios(codigo_consultorio) )" ); llenar_tablas(sqLiteDatabase); } public void llenar_tablas(SQLiteDatabase sqLiteDatabase){ sqLiteDatabase.execSQL("insert into " + TABLA_DATOS_MEDICO + " VALUES('123456798','Doctor Santiago Gonzales Noreña','06:00','18:00')," + "('9876544321','Doctor Pablo Andres Serna','12:00','00:00')," + "('3219876543','Doctor Juan Esteban Correa','05:00','17:00')," + "('111122233344','Doctor Jhon Jairo Hernandez','05:00','05:00')" ); sqLiteDatabase.execSQL("insert into " + TABLA_CONSULTORIO + " VALUES('1','G69','Urología')," + " ('2','G70','Proctología')," + " ('3','G71','Mastología')," + " ('4','G72','Ginecología')" ); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { sqLiteDatabase.execSQL("DROP TABLE " + TABLA_CITAS); sqLiteDatabase.execSQL("DROP TABLE " + TABLA_DATOS_MEDICO); sqLiteDatabase.execSQL("DROP TABLE " + TABLA_CONSULTORIO); sqLiteDatabase.execSQL("DROP TABLE " + TABLA_USUARIO); onCreate(sqLiteDatabase); } }
Comentarios
Publicar un comentario