Exemple #1
0
    // update a row
    void UpdateRow(string id, string name)
    {
        // list of data to be updated
        List <SQLiteDB.DB_DataPair> dataList = new List <SQLiteDB.DB_DataPair> ();

        // data to be updated
        SQLiteDB.DB_DataPair data = new SQLiteDB.DB_DataPair();
        data.fieldName = "Name";
        data.value     = name;

        dataList.Add(data);

        // row to be updated
        SQLiteDB.DB_ConditionPair condition = new SQLiteDB.DB_ConditionPair();
        condition.fieldName = "Id";
        condition.value     = id;
        condition.condition = SQLiteDB.DB_Condition.EQUAL_TO;

        int i = db.Update("Users", dataList, condition);

        if (i > 0)
        {
            Debug.Log(i + " Record Updated!");
            _name = "";
            _id   = "";
            Refresh();
        }
    }
Exemple #2
0
    // delete perticular id
    void DeleteRow(string id)
    {
        SQLiteDB.DB_ConditionPair condition = new SQLiteDB.DB_ConditionPair();
        // delete from Users where Id = id
        condition.fieldName = "Id";
        condition.value     = id;
        condition.condition = SQLiteDB.DB_Condition.EQUAL_TO;

        int i = db.DeleteRow("Users", condition);

        if (i > 0)
        {
            Debug.Log(i + " Record Deleted!");
            Refresh();
        }
    }
    public bool Delete(string primaryKeyValue)
    {
        bool successful = false;

        SQLiteDB.DB_ConditionPair condition = new SQLiteDB.DB_ConditionPair();

        condition.fieldName = _primaryKeyProperty.Name;
        condition.value     = primaryKeyValue;
        condition.condition = SQLiteDB.DB_Condition.EQUAL_TO;

        if (_db.DeleteRow(_tableIdentifier, condition) > 0)
        {
            successful = true;
        }

        return(successful);
    }
    public bool Update(T item)
    {
        bool successful = false;

        List <SQLiteDB.DB_DataPair> dataPairList = new List <SQLiteDB.DB_DataPair>();

        SQLiteDB.DB_DataPair      data      = new SQLiteDB.DB_DataPair();
        SQLiteDB.DB_ConditionPair condition = new SQLiteDB.DB_ConditionPair();

        foreach (var property in _itemProperties)
        {
            // if the property isn't being ignored
            if (property.GetCustomAttributes(typeof(ColumnIgnoreAttribute), false).Length == 0)
            {
                // if isn't primary key
                if (property.GetCustomAttributes(typeof(PrimaryKeyAttribute), false).Length == 0)
                {
                    data.fieldName = property.Name;
                    data.value     = ConvertValueToString(item, property);
                    dataPairList.Add(data);
                }
                // else is, it can't be updated but instead used for finding record to update
                else
                {
                    condition.fieldName = property.Name;
                    condition.value     = ConvertValueToString(item, property);
                    condition.condition = SQLiteDB.DB_Condition.EQUAL_TO;
                }
            }
        }

        if (_db.Update(_tableIdentifier, dataPairList, condition) > 0)
        {
            successful = true;
        }

        return(successful);
    }