title: Make insert or update to SQLite taking care of empty table
body: <p>The logic has to decide whether it will <code>insert</code> or <code>update</code> the table and yet it has to check if the table is not empty since. </p>
  
  <p>So the current version of the code looks like this</p>
  
  <pre><code>if ((new XYZController(mContext)).getCount() == 0) {
      new XYZController(mContext).insert(object);
  } else {
      XYZObject obj = (new XYZController(mContext)).getByString(string);
      if (obj == null) {
          new XYZController(mContext).insert(object);
      } else {
          new XYZController(mContext).update(object);
      }
  }
  </code></pre>
  
  <p>Since I cannot do <code>WHERE</code> query on empty SQLite table, I have to make additional "if empty" check.</p>
  
  <p>Is there a way to omit such flow and just do 1 insert and 1 update caring if the table is empty or not?</p>
  
  <p>PS. If we try to make a <code>WHERE</code> query on empty table, the app will break on the <code>cursor.getString()</code></p>
  
  <pre><code>public XYZModel getByString(String s) {
      String selectQuery = "SELECT * FROM " + TABLE_XYZ
              + " WHERE " + COLUMN + "='" + s + "'";
      Cursor cursor = getRow(selectQuery);
  
      XYZModel walk = null;
      if (cursor != null) {
          cursor.moveToFirst();
          obj = new XYZModel(cursor.getString(1), cursor.getString(2),
                  cursor.getString(3));
      }
      if (obj == null)
          obj = new XYZModel();
  
      return obj;
  }
  </code></pre>