Android Question Adding database tables -UpdateDB2_3

Discussion in 'Android Questions' started by Arf, May 29, 2015.

  1. Arf

    Arf Active Member Licensed User

    I use SQL for a database of patients, the original database was created as follows:
    Code:
    Sub UpdateDB1_2(sq As SQL)
        
    'empty database, lets create all required tables
        Dim m As Map
        m.Initialize 
    'clear the map
        m.Put("Patient_No", DBUtils.DB_TEXT)
        m.Put(
    "First_Name", DBUtils.DB_TEXT)
        m.Put(
    "Last_Name", DBUtils.DB_TEXT)
        m.Put(
    "Date_of_Birth", DBUtils.DB_INTEGER)
        m.Put(
    "Sex", DBUtils.DB_TEXT)
        m.Put(
    "Patient_ID", DBUtils.DB_INTEGER)
        DBUtils.CreateTable(sq, 
    "Patients", m, ""'no primary key assigned
       
        m.Initialize 
    'clear the map
        m.Put("ExamTime", DBUtils.DB_INTEGER)
        m.Put(
    "ExamPatient_ID", DBUtils.DB_INTEGER)
        m.Put(
    "ExamTestNum", DBUtils.DB_INTEGER)
        m.Put(
    "ExamData", DBUtils.DB_BLOB)
        DBUtils.CreateTable(sq, 
    "Exams", m, ""'no primary key assigned
        DBUtils.SetDBVersion(sq, 2)
    End Sub
    And now I need to add a height parameter to my stored patient data. So I can see how to create a similar UpdateDB2_3 function to do that, but I am not sure how to go about actually adding height to the map within that function. I don't want to delete my existing DDB and start over.

    Would it be as simple as this, or will this damage my existing database?
    Code:
    Sub UpdateDB2_3(sq As SQL)
        
    Dim m As Map
        m.Initialize 
    'clear the map
        m.Put("Patient_No", DBUtils.DB_TEXT)
        m.Put(
    "First_Name", DBUtils.DB_TEXT)
        m.Put(
    "Last_Name", DBUtils.DB_TEXT)
        m.Put(
    "Date_of_Birth", DBUtils.DB_INTEGER)
        m.Put(
    "Sex", DBUtils.DB_TEXT)
        m.Put(
    "Patient_ID", DBUtils.DB_INTEGER)
       
        
    'now add height
        m.Put("Patient_Height", DBUtils.DB_INTEGER)
       
        DBUtils.CreateTable(sq, 
    "Patients", m, ""'no primary key assigned
        DBUtils.SetDBVersion(sq, 3)
    End Sub
     
  2. JTmartins

    JTmartins Active Member Licensed User

    If you create a table with the same name you will eventualy get an error..Actualy I never tried this. Anyway if you do not get an error a new table will be created and you will loose all data already inserted.

    Your best option I think it will be execute a SQLite comand directly on the table as :

    ALTERTABLE Patients ADDCOLUMN Patient_Height Integer
     
    DonManfred likes this.
  3. Arf

    Arf Active Member Licensed User

    Thanks, I shall give it a try.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice