Пример #1
0
  /**
   * Debug/bootstrap testing method to blow away all data in the core model tables <br>
   * <br>
   * rapidandroid_form <br>
   * rapidandroid_field <br>
   * rapidandroid_fieldtype
   */
  public static void ClearFormTables() {

    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    db.execSQL("delete from " + RapidSmsDBConstants.FieldType.TABLE);
    db.execSQL("delete from " + RapidSmsDBConstants.Field.TABLE);
    db.execSQL("delete from " + RapidSmsDBConstants.Form.TABLE);

    Log.v("dimagi", "wiped the form/field/fieldtype/formdata table for debug purposes");
  }
Пример #2
0
  /**
   * Generate the fully typed out table that parsed data will be inserted into when SMS messages
   * come in.
   *
   * @param form
   */
  public static void generateFormTable(Form form) {
    // dmyung: 1/19/2009
    // For the intial run through this is a bit hacky.

    // for each form, create a new sql table create table script
    // do do that get the form prefix and get a foriegn key back to the
    // message table
    // after that, create all the columns
    // do do this we make a switch statement and we will support the SQLite
    // datatypes.

    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    try {
      Cursor formdatacursor =
          db.rawQuery("select * from formdata_" + form.getPrefix().replace("@", "") + ";", null);
      if (formdatacursor.getCount() > 0) {
        return;
      } else {
        db.execSQL("drop table formdata_" + form.getPrefix());
      }
    } catch (SQLException ex) {
      // table likely doesn't exist, we're good to go!

    }

    StringBuilder sb = new StringBuilder();
    sb.append("create table formdata_");
    sb.append(form.getPrefix().replace("@", ""));
    sb.append(" (");
    sb.append(" \"_id\" integer not null PRIMARY KEY, ");
    sb.append(" \"message_id\" integer not null references \"message\", ");

    org.rapidsms.java.core.model.Field[] fields = form.getFields();
    int fieldcount = fields.length;

    boolean last = false;
    for (int i = 0; i < fieldcount; i++) {
      if (i == fieldcount - 1) {
        last = true;
      }
      getFieldDeclaration(fields[i], sb, last);
    }

    sb.append(" );");

    db.execSQL(sb.toString());
  }