Example #1
0
        private static int InternalSaveToTable(SQLiteConnection conn, SQLiteTransaction trans, Action <SqlTableUpdateBuilder> code)
        {
            var builder = new SqlTableUpdateBuilder();

            code.Invoke(builder);

            var countCmd = builder.BuildCount(conn, trans);
            var col1     = countCmd.ExecuteScalar();

            if (col1 == null)
            {
                throw new Exception($"Unable to select from table [{builder.TableName}].");
            }
            var count = Convert.ToInt32(col1);

            if (count == 0)
            {
                var insertCmd = builder.BuildInsert(conn, trans);
                return(insertCmd.ExecuteNonQuery());
            }
            else if (count == 1)
            {
                var updateCmd = builder.BuildUpdate(conn, trans);
                return(updateCmd.ExecuteNonQuery());
            }
            else
            {
                throw new Exception($"Unable to save to table {builder.TableName}: Duplicate Keys Found.");
            }
        }
Example #2
0
        private static int InternalUpdateTable(SQLiteConnection conn, SQLiteTransaction trans, Action <SqlTableUpdateBuilder> code)
        {
            var builder = new SqlTableUpdateBuilder();

            code.Invoke(builder);
            var cmd = builder.BuildUpdate(conn, trans);

            return(cmd.ExecuteNonQuery());
        }
Example #3
0
        private static int InternalSafeInsertIntoTable(SQLiteConnection conn, SQLiteTransaction trans, Action <SqlTableUpdateBuilder> code)
        {
            int result = 0;

            var builder = new SqlTableUpdateBuilder();

            code.Invoke(builder);

            var countCmd = builder.BuildCount(conn, trans);
            var col1     = countCmd.ExecuteScalar();

            if (col1 == null)
            {
                throw new Exception($"Unable to select from table [{builder.TableName}].");
            }
            var count = Convert.ToInt32(col1);

            if (count == 0)
            {
                var insertCmd = builder.BuildInsert(conn, trans);
                result = insertCmd.ExecuteNonQuery();
            }
            return(result);
        }