public Cursor getSurveyAnswer(DatabaseOperations dop) {

    SQLiteDatabase SQ = dop.getReadableDatabase();
    String selectQuery = "SELECT * FROM " + TableInfo_Survey_Answer.TABLE_NAME;
    Cursor c = SQ.rawQuery(selectQuery, null);
    return c;
  }
 public long insertQuestionnaire_Field_Association(
     DatabaseOperations dop,
     String questionnaire_id,
     int field_id,
     String required,
     String field_type,
     String option_value,
     int order) {
   try {
     SQLiteDatabase SQ = dop.getWritableDatabase();
     ContentValues cv = new ContentValues();
     cv.put(Table_Info_Questionnaire_Field_Association.QUESTIONNAIRE_ID, questionnaire_id);
     cv.put(Table_Info_Questionnaire_Field_Association.FIELD_ID, field_id);
     cv.put(Table_Info_Questionnaire_Field_Association.REQUIRED, required);
     cv.put(Table_Info_Questionnaire_Field_Association.FIELD_TYPE, field_type);
     cv.put(Table_Info_Questionnaire_Field_Association.OPTION_VALUE, option_value);
     cv.put(Table_Info_Questionnaire_Field_Association.ORDER, order);
     long k =
         SQ.insertWithOnConflict(
             Table_Info_Questionnaire_Field_Association.TABLE_NAME,
             null,
             cv,
             SQLiteDatabase.CONFLICT_REPLACE);
     Log.d("database operation", "one row inserted");
     return k;
   } catch (Exception ex) {
     return -1;
   }
 }
  public Cursor getFieldTable(DatabaseOperations dop) {

    SQLiteDatabase SQ = dop.getReadableDatabase();
    String selectQuery = "SELECT * FROM " + Table_Info_Field_Table.TABLE_NAME;
    Cursor c = SQ.rawQuery(selectQuery, null);
    return c;
  }
 public long insertSurveyQuestion(
     DatabaseOperations dop,
     String questionID,
     String uniquecode,
     String creationdate,
     String lastupdate,
     String questionnaireID,
     String status,
     String required,
     String other,
     String question_type,
     String field_type,
     String question,
     String option1,
     String option2,
     String option3,
     String option4,
     String option5,
     String option6,
     String option7,
     String option8,
     String option9,
     int display_order) {
   try {
     question_type = question_type.replace("'", "''");
     question = question.replace("'", "''");
     field_type = field_type.replace("'", "''");
     SQLiteDatabase SQ = dop.getWritableDatabase();
     ContentValues cv = new ContentValues();
     cv.put(TableInfo_Survey_Question.QUESTION_ID, questionID);
     cv.put(TableInfo_Survey_Question.UNIQUE_CODE, uniquecode);
     cv.put(TableInfo_Survey_Question.CREATION_DATE, creationdate);
     cv.put(TableInfo_Survey_Question.LAST_UPDATE, lastupdate);
     cv.put(TableInfo_Survey_Question.QUESTIONNAIRE_ID, questionnaireID);
     cv.put(TableInfo_Survey_Question.STATUS, status);
     cv.put(TableInfo_Survey_Question.REQUIRED, required);
     cv.put(TableInfo_Survey_Question.OTHER, other);
     cv.put(TableInfo_Survey_Question.QUESTION_TYPE, question_type);
     cv.put(TableInfo_Survey_Question.FIELD_TYPE, field_type);
     cv.put(TableInfo_Survey_Question.QUESTION, question);
     cv.put(TableInfo_Survey_Question.OPTION1, option1);
     cv.put(TableInfo_Survey_Question.OPTION2, option2);
     cv.put(TableInfo_Survey_Question.OPTION3, option3);
     cv.put(TableInfo_Survey_Question.OPTION4, option4);
     cv.put(TableInfo_Survey_Question.OPTION5, option5);
     cv.put(TableInfo_Survey_Question.OPTION6, option6);
     cv.put(TableInfo_Survey_Question.OPTION7, option7);
     cv.put(TableInfo_Survey_Question.OPTION8, option8);
     cv.put(TableInfo_Survey_Question.OPTION9, option9);
     cv.put(TableInfo_Survey_Question.DISPLAY_ORDER, display_order);
     long k =
         SQ.insertWithOnConflict(
             TableInfo_Survey_Question.TABLE_NAME, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
     Log.d("database operation", "one row inserted");
     return k;
   } catch (Exception ex) {
     return -1;
   }
 }
 public long insertFieldTable(DatabaseOperations dop, String field_name) {
   try {
     SQLiteDatabase SQ = dop.getWritableDatabase();
     ContentValues cv = new ContentValues();
     cv.put(Table_Info_Field_Table.FIELD_NAME, field_name);
     long k =
         SQ.insertWithOnConflict(
             Table_Info_Field_Table.TABLE_NAME, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
     Log.d("database operation", "one row inserted");
     return k;
   } catch (Exception ex) {
     return -1;
   }
 }
  public Cursor getSurveyQuestions(DatabaseOperations dop, String questionnaireID) {

    SQLiteDatabase SQ = dop.getReadableDatabase();
    String selectQuery =
        "SELECT * FROM "
            + TableInfo_Survey_Question.TABLE_NAME
            + " WHERE "
            + TableInfo_Survey_Question.QUESTIONNAIRE_ID
            + " = "
            + questionnaireID
            + " ORDER BY "
            + TableInfo_Survey_Question.DISPLAY_ORDER
            + " ASC";
    Cursor c = SQ.rawQuery(selectQuery, null);

    return c;
  }
  public long insertSurveyAnswer(
      DatabaseOperations dop,
      String uniqueUserId,
      String questionnaireID,
      String questionID,
      String question_type,
      String answer,
      String required,
      String field_name,
      String field_value,
      String field_type,
      String field_required,
      String image_Qid,
      String image_question_type,
      String image_question_required,
      String imagearray) {
    try {
      field_name = field_name.replace("'", "''");

      SQLiteDatabase SQ = dop.getWritableDatabase();
      ContentValues cv = new ContentValues();
      cv.put(TableInfo_Survey_Answer.UNIQUE_USER_ID, uniqueUserId);
      cv.put(TableInfo_Survey_Answer.QUESTIONNAIRE_ID, questionnaireID);
      cv.put(TableInfo_Survey_Answer.QUESTION_ID, questionID);
      cv.put(TableInfo_Survey_Answer.QUESTION_TYPE, question_type);
      cv.put(TableInfo_Survey_Answer.ANSWER, answer);
      cv.put(TableInfo_Survey_Answer.REQUIRED, required);
      cv.put(TableInfo_Survey_Answer.FIELD_NAME, field_name);
      cv.put(TableInfo_Survey_Answer.FIELD_VALUE, field_value);
      cv.put(TableInfo_Survey_Answer.FIELD_TYPE, field_type);
      cv.put(TableInfo_Survey_Answer.FIELD_REQUIRED, field_required);
      cv.put(TableInfo_Survey_Answer.IMAGE_QID, image_Qid);
      cv.put(TableInfo_Survey_Answer.IMAGE_QUESTION_TYPE, image_question_type);
      cv.put(TableInfo_Survey_Answer.IMAGE_QUESTION_REQUIRED, image_question_required);
      cv.put(TableInfo_Survey_Answer.IMAGE_ARRAY, imagearray);
      long k =
          SQ.insertWithOnConflict(
              TableInfo_Survey_Answer.TABLE_NAME, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
      Log.d("database operation", "one row inserted");
      return k;
    } catch (Exception ex) {
      return -1;
    }
  }
 public long insertListOfSurveyQuestion(
     DatabaseOperations dop,
     String questionnaireID,
     String creationdate,
     String lastupdate,
     String uniquecode,
     String companyID,
     String agentID,
     String screen_type,
     String status,
     String title,
     String font,
     String message_type,
     String completion_text) {
   try {
     completion_text = completion_text.replace("'", "''");
     title = title.replace("'", "''");
     SQLiteDatabase SQ = dop.getWritableDatabase();
     ContentValues cv = new ContentValues();
     cv.put(TableInfo_ListOf_Survey.QUESTIONNAIRE_ID, questionnaireID);
     cv.put(TableInfo_ListOf_Survey.CREATEION_DATE, creationdate);
     cv.put(TableInfo_ListOf_Survey.LAST_UPDATED, lastupdate);
     cv.put(TableInfo_ListOf_Survey.UNIQUE_CODE, uniquecode);
     cv.put(TableInfo_ListOf_Survey.COMPANY_ID, companyID);
     cv.put(TableInfo_ListOf_Survey.AGENT_ID, agentID);
     cv.put(TableInfo_ListOf_Survey.SCREEN_TYPE, screen_type);
     cv.put(TableInfo_ListOf_Survey.STATUS, status);
     cv.put(TableInfo_ListOf_Survey.TITLE, title);
     cv.put(TableInfo_ListOf_Survey.FONT, font);
     cv.put(TableInfo_ListOf_Survey.MESSAGE_TYPE, message_type);
     cv.put(TableInfo_ListOf_Survey.COMPLETION_TEXT, completion_text);
     long k =
         SQ.insertWithOnConflict(
             TableInfo_ListOf_Survey.TABLE_NAME, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
     Log.d("database operation", "one row inserted");
     return k;
   } catch (Exception ex) {
     return -1;
   }
 }
  public Cursor getQuestionnaireFieldAssociation(DatabaseOperations dop, String questionnaireId) {

    SQLiteDatabase SQ = dop.getReadableDatabase();
    String selectQuery =
        "SELECT "
            + Table_Info_Questionnaire_Field_Association.TABLE_NAME
            + ".* ,"
            + Table_Info_Field_Table.TABLE_NAME
            + "."
            + Table_Info_Field_Table.FIELD_NAME
            + " FROM "
            + Table_Info_Questionnaire_Field_Association.TABLE_NAME
            + " INNER JOIN "
            + Table_Info_Field_Table.TABLE_NAME
            + " ON "
            + Table_Info_Questionnaire_Field_Association.TABLE_NAME
            + "."
            + Table_Info_Field_Table.FIELD_ID
            + " = "
            + Table_Info_Field_Table.TABLE_NAME
            + "."
            + Table_Info_Questionnaire_Field_Association.FIELD_ID
            + " WHERE "
            + Table_Info_Questionnaire_Field_Association.TABLE_NAME
            + "."
            + Table_Info_Questionnaire_Field_Association.QUESTIONNAIRE_ID
            + "= '"
            + questionnaireId
            + "' ORDER BY "
            + Table_Info_Questionnaire_Field_Association.ORDER
            + " ASC";

    Log.i("database join", selectQuery);
    Cursor c = SQ.rawQuery(selectQuery, null);
    return c;
  }
  public int getFieldId(DatabaseOperations dop, String field_name) {

    field_name = field_name.replace("'", "''");
    int id;
    SQLiteDatabase SQ = dop.getReadableDatabase();
    String selectQuery =
        "SELECT "
            + Table_Info_Field_Table.FIELD_ID
            + " FROM "
            + Table_Info_Field_Table.TABLE_NAME
            + " WHERE "
            + Table_Info_Field_Table.FIELD_NAME
            + " = '"
            + field_name
            + "'";
    // String selectQuery = "SELECT " +  "* FROM " + Table_Info_Field_Table.TABLE_NAME ;
    Cursor c = SQ.rawQuery(selectQuery, null);
    if (c.moveToFirst()) {
      id = c.getInt(c.getColumnIndex(Table_Info_Field_Table.FIELD_ID));
    } else {
      id = -1;
    }
    return id;
  }