Example #1
0
        public SQLiteCommand GetInsertCommand(T instance)
        {
            map = Reflector.BuildMapFromInstance(instance);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("insert into [{0}] ", map.TableName);
            sb.Append("(");

            // Build columns part
            AppendColumnsForInsert(sb);

            sb.Append(") values (");

            // Build values part
            AppendValuesForInsert(sb);

            sb.Append("); SELECT last_insert_rowid()");

            SQLiteCommand command = BuildCommand(sb);

            // Copy parameters to command
            CopyColumnValuesToCommand(command);

            return(command);
        }
Example #2
0
        public SQLiteCommand GetDeleteCommand(T instance)
        {
            map = Reflector.BuildMapFromInstance(instance);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("delete from [{0}] ", map.TableName);
            sb.AppendFormat(" where [{0}]=@{0}", map.PrimaryKey.ColumName);

            SQLiteCommand command = BuildCommand(sb);

            // Copy parameters to command
            CopyColumnValuesToCommand(command);

            command.Parameters.AddWithValue("@" + map.PrimaryKey.ColumName, map.PrimaryKey.Value);

            return(command);
        }
Example #3
0
        public SQLiteCommand GetUpdateCommand(T instance, params string[] columns)
        {
            map = Reflector.BuildMapFromInstance(instance);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("update [{0}] set ", map.TableName);

            // Build columns/values part
            AppendColumnsForUpdate(sb, columns);

            sb.AppendFormat(" where [{0}]=@{0}", map.PrimaryKey.ColumName);

            SQLiteCommand command = BuildCommand(sb);

            // Copy parameters to command
            CopyColumnValuesToCommand(command);

            command.Parameters.AddWithValue("@" + map.PrimaryKey.ColumName, map.PrimaryKey.Value);

            return(command);
        }