Beispiel #1
0
        void ExportGeometry(IGeometry g)
        {
            // c.f. FdoToolbox bulk copy? - FdoBatchedOutputOperation
            using (IInsert cmd = m_Connection.CreateCommand(CommandType.CommandType_Insert) as IInsert)
            {
                cmd.SetFeatureClassName("FC");

                PropertyValueCollection pvc = cmd.PropertyValues;

                //PropertyValue pvId = new PropertyValue();
                //pvId.SetName("ID");
                //pvId.Value = new Int32Value(id);
                //pvc.Add(pvId);

                GeometryValue gv     = new GeometryValue(m_Factory.GetFgf(g));
                PropertyValue pvGeom = new PropertyValue();
                pvGeom.SetName("Geometry");
                pvGeom.Value = gv;
                pvc.Add(pvGeom);

                try
                {
                    IFeatureReader reader = cmd.Execute();
                    reader.Dispose();
                    m_NumOk++;
                }

                catch
                {
                    m_NumFail++;
                }
            }
        }
Beispiel #2
0
        public OnConflictDoUpdate(IInsert <T1> insert, Expression <Func <T1, object> > columns = null)
        {
            _pgsqlInsert = insert as PostgreSQLInsert <T1>;
            if (_pgsqlInsert == null)
            {
                throw new Exception("OnConflictDoUpdate 是 FreeSql.Provider.PostgreSQL 特有的功能");
            }

            if (columns != null)
            {
                var colsList = new List <ColumnInfo>();
                var cols     = _pgsqlInsert.InternalCommonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, columns?.Body, false, null).ToDictionary(a => a, a => true);
                foreach (var col in _pgsqlInsert.InternalTable.Columns.Values)
                {
                    if (cols.ContainsKey(col.Attribute.Name))
                    {
                        colsList.Add(col);
                    }
                }
                _columns = colsList.ToArray();
            }
            if (_columns == null || _columns.Any() == false)
            {
                _columns = _pgsqlInsert.InternalTable.Primarys;
            }
            if (_columns.Any() == false)
            {
                throw new Exception("OnConflictDoUpdate 功能要求实体类必须设置 IsPrimary 属性");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a new coordinate system to the database
        /// </summary>
        /// <param name="cs"></param>
        public void AddProjection(CoordinateSystemDefinition cs)
        {
            using (var conn = CreateSqliteConnection())
            {
                conn.Open();
                using (IInsert cmd = (IInsert)conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Insert))
                {
                    cmd.SetFeatureClassName("Projections");
                    cmd.PropertyValues.Add(new OSGeo.FDO.Commands.PropertyValue("Name", new StringValue(cs.Name)));
                    cmd.PropertyValues.Add(new OSGeo.FDO.Commands.PropertyValue("Description", new StringValue(cs.Description)));
                    cmd.PropertyValues.Add(new OSGeo.FDO.Commands.PropertyValue("WKT", new StringValue(cs.Wkt)));

                    int affected = 0;
                    using (var reader = cmd.Execute())
                    {
                        while (reader.ReadNext())
                        {
                            affected++;
                        }
                        reader.Close();
                    }

                    if (affected == 1)
                    {
                        _Projections.Add(cs);
                        LoggingService.InfoFormatted("Coordinate System {0} added to database", cs.Name);
                    }
                }
                conn.Close();
            }
        }
        public OdbcPostgreSQLOnConflictDoUpdate(IInsert <T1> insert, Expression <Func <T1, object> > columns = null)
        {
            _pgsqlInsert = insert as OdbcPostgreSQLInsert <T1>;
            if (_pgsqlInsert == null)
            {
                throw new Exception(CoreStrings.S_Features_Unique("OnConflictDoUpdate", "Odbc/PostgreSQL"));
            }
            if (_pgsqlInsert._noneParameterFlag == "c")
            {
                _pgsqlInsert._noneParameterFlag = "cu";
            }

            if (columns != null)
            {
                var colsList = new List <ColumnInfo>();
                var cols     = _pgsqlInsert.InternalCommonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null).ToDictionary(a => a, a => true);
                foreach (var col in _pgsqlInsert.InternalTable.Columns.Values)
                {
                    if (cols.ContainsKey(col.Attribute.Name))
                    {
                        colsList.Add(col);
                    }
                }
                _tempPrimarys = colsList.ToArray();
            }
            if (_tempPrimarys == null || _tempPrimarys.Any() == false)
            {
                _tempPrimarys = _pgsqlInsert.InternalTable.Primarys;
            }
            if (_tempPrimarys.Any() == false)
            {
                throw new Exception(CoreStrings.S_OnConflictDoUpdate_MustIsPrimary);
            }
        }
Beispiel #5
0
        public void To_String()
        {
            IAlias  person = sql.Alias("person");
            IInsert insert = sql.Insert().Into(person);

            Assert.Equal("INSERT INTO person", insert.ToString());
        }
Beispiel #6
0
 public RunCase(IInsert insert, Call[] calls, int iterationsCount)
 {
     _calls           = calls;
     _insert          = insert;
     _dbUtil          = new DbUtil();
     _iterationsCount = iterationsCount;
 }
Beispiel #7
0
        protected override DbCommand OnBuildInsertCommand(IInsert Query)
        {
            SqlCommand    command;
            StringBuilder sql;
            int           index;

            sql = new StringBuilder();
            sql.Append("INSERT INTO ");
            sql.Append(OnFormatTableName(Query.Table));

            if (Query.Setters.Any())
            {
                sql.Append(" (");
                sql.Append(String.Join(", ", Query.Setters.Select(item => OnFormatColumnName(item.Column))));
                sql.Append(") VALUES (");

                index = 0;
                sql.Append(String.Join(", ", Query.Setters.Select(item => OnFormatParameterName(item.Column.Name, ref index))));
                sql.Append(")");
            }

            command = new SqlCommand(sql.ToString());
            index   = 0;
            OnBuildParameters(command, Query.Setters, ref index);

            return(command);
        }
Beispiel #8
0
 static SqlTemplate()
 {
     Select  = new SelectTemplate();
     Update  = new UpdateTemplate();
     Delete  = new DeleteTemplate();
     Insert  = new InsertTemplate();
     Repeate = new RepeateTemplate();
 }
 public QueryRepository(IDelete delete, IInsert insert, ISelectQuery selectQuery, ISelectQueryParam selectQueryParam, IUpdate update)
 {
     _delete           = delete;
     _insert           = insert;
     _selectQuery      = selectQuery;
     _selectQueryParam = selectQueryParam;
     _update           = update;
 }
Beispiel #10
0
        public void Into_Null()
        {
            IInsert insert = sql.Insert();

            Exception ex = Assert.Throws <CompileException>(() => engine.Compile(insert));

            Assert.Equal("Into value is null.", ex.Message);
        }
Beispiel #11
0
 /// <summary>
 /// Inserts the elements into the collection at the specified index, one by one.
 /// </summary>
 /// <typeparam name="TElement">The type of the elements in the collection.</typeparam>
 /// <param name="collection">This collection.</param>
 /// <param name="index">The index at which the <paramref name="elements"/> should be inserted.</param>
 /// <param name="elements">The elements to insert.</param>
 public static void Insert <TElement>(this IInsert <Index, TElement> collection, Index index, ReadOnlySpan <TElement> elements)
 {
     for (Int32 i = 0; i < elements.Length; i++)
     {
         collection.Insert(index, elements[i]);
         index = index.Value + 1;
     }
 }
 public OdbcMySqlOnDuplicateKeyUpdate(IInsert <T1> insert)
 {
     _mysqlInsert = insert as OdbcMySqlInsert <T1>;
     if (_mysqlInsert == null)
     {
         throw new Exception("OnDuplicateKeyUpdate 是 FreeSql.Provider.Odbc/MySql 特有的功能");
     }
 }
Beispiel #13
0
 public static unsafe void Insert <TElement>(this IInsert <Index, TElement> collection, Index index, TElement *elements, Int32 length) where TElement : unmanaged
 {
     for (Int32 i = 0; i < length; i++)
     {
         collection.Insert(index, elements[i]);
         index = index.Value + 1;
     }
 }
Beispiel #14
0
 public OnDuplicateKeyUpdate(IInsert <T1> insert)
 {
     _mysqlInsert = insert as MySqlInsert <T1>;
     if (_mysqlInsert == null)
     {
         throw new Exception("OnDuplicateKeyUpdate 是 FreeSql.Provider.MySql/FreeSql.Provider.MySqlConnector 特有的功能");
     }
 }
Beispiel #15
0
        /*protected ITryFunction<int> Try<TTable>(ISelectIdentity<TTable> Query, [CallerMemberName]string MethodName = null)
         * {
         *      return Try<int>(() =>
         *      {
         *              object result;
         *
         *              result = this.database.Execute(Query);
         *              return (int)result;
         *      }
         *      , MethodName) ;
         * }*/

        protected ITryFunction <object> Try(IInsert Query, [CallerMemberName] string MethodName = null)
        {
            return(Try(() =>
            {
                return this.database.Execute(Query, new SelectIdentity());
            }
                       , MethodName));
        }
Beispiel #16
0
        public void Insert_String()
        {
            IInsert insert = sql.Insert().Into("person");

            QueryResult result = engine.Compile(insert);

            Assert.Equal("INSERT INTO \"person\"", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Beispiel #17
0
 public RelationHandler(string splites, Type entity_type) : base(splites, entity_type)
 {
     _mapping         = new Dictionary <MemberInfo, RelationAttribute>();
     _select_template = new SelectTemplate();
     _update_template = new UpdateTemplate();
     _delete_template = new DeleteTemplate();
     _insert_template = new InsertTemplate();
     Store();
 }
Beispiel #18
0
 public InsertHandler(string splites, Type entity_type) : base(splites, entity_type)
 {
     _template          = new InsertTemplate();
     _model.ColFunction = (item) => { return(_model.Column(item)); };
     if (!_primary_manually)
     {
         _model.AddIgnores(_primary_member);
     }
 }
Beispiel #19
0
        public void Add_Params()
        {
            IAlias  person = sql.Alias("person");
            IInsert insert = sql.Insert().Into(person).Add(person["Name"], person["SurName"]);

            QueryResult result = engine.Compile(insert);

            Assert.Equal("INSERT INTO \"person\" (\"Name\", \"SurName\")", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
        public static IInsert <T1> DisableGlobalAsTable <T1>(this IInsert <T1> that) where T1 : class
        {
            var s0p = (that as InsertProvider <T1>);

            if (s0p != null)
            {
                s0p._tableRule = null;
            }
            return(that);
        }
Beispiel #21
0
        public void Insert_Expression()
        {
            Person  person = null;
            IInsert insert = sql.Insert().Into(() => person);

            QueryResult result = engine.Compile(insert);

            Assert.Equal("INSERT INTO \"Person\"", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Beispiel #22
0
        public void Add_Expression_Params()
        {
            Person  person = null;
            IInsert insert = sql.Insert().Into(() => person).Add(() => person.Name, () => person.SurName);

            QueryResult result = engine.Compile(insert);

            Assert.Equal("INSERT INTO \"Person\" (\"Name\", \"SurName\")", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Beispiel #23
0
 public SQL()
 {
     sql        = new StringBuilder();
     twhere     = new TWhere(this.sql);
     tfrom      = new TFrom(this.sql);
     tselect    = new TSelect(this.sql, this.tfrom, twhere);
     tinsert    = new TInsert(this.sql, this.tselect);
     tcondition = new TCondition(sql);
     tdelete    = new TDelete(sql);
     tupdate    = new TUpdate(sql);
 }
Beispiel #24
0
    /// <summary>
    /// MySql 特有的功能,Insert Ignore Into
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <param name="that"></param>
    /// <returns></returns>
    public static IInsert <T1> MySqlIgnoreInto <T1>(this IInsert <T1> that) where T1 : class
    {
        var _mysqlInsert = that as MySqlInsert <T1>;

        if (_mysqlInsert == null)
        {
            throw new Exception(CoreStrings.S_Features_Unique("MySqlIgnoreInto", "MySql/FreeSql.Provider.MySqlConnector"));
        }
        _mysqlInsert.InternalIsIgnoreInto = true;
        return(that);
    }
Beispiel #25
0
 /// <summary>
 /// Inserts the elements into the collection at the specified index, one by one.
 /// </summary>
 /// <typeparam name="TElement">The type of the elements in the collection.</typeparam>
 /// <typeparam name="TEnumerator">The type of the enumerator for the collection.</typeparam>
 /// <param name="collection">This collection.</param>
 /// <param name="index">The index at which the <paramref name="elements"/> should be inserted.</param>
 /// <param name="elements">The elements to insert.</param>
 public static void Insert <TElement, TEnumerator>(this IInsert <Index, TElement> collection, Index index, IGetEnumerator <TElement, TEnumerator>?elements) where TEnumerator : notnull, ICurrent <TElement>, IMoveNext
 {
     if (elements is not null)
     {
         foreach (TElement element in elements)
         {
             collection.Insert(index, element);
             index = index.Value + 1;
         }
     }
 }
Beispiel #26
0
    /// <summary>
    /// MySql 特有的功能,Insert Ignore Into
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <param name="that"></param>
    /// <returns></returns>
    public static IInsert <T1> MySqlIgnoreInto <T1>(this IInsert <T1> that) where T1 : class
    {
        var _mysqlInsert = that as MySqlInsert <T1>;

        if (_mysqlInsert == null)
        {
            throw new Exception("MySqlIgnoreInto 是 FreeSql.Provider.MySql/FreeSql.Provider.MySqlConnector 特有的功能");
        }
        _mysqlInsert.InternalIsIgnoreInto = true;
        return(that);
    }
Beispiel #27
0
 public OnDuplicateKeyUpdate(IInsert <T1> insert)
 {
     _mysqlInsert = insert as MySqlInsert <T1>;
     if (_mysqlInsert == null)
     {
         throw new Exception(CoreStrings.S_Features_Unique("OnDuplicateKeyUpdate", "MySql/FreeSql.Provider.MySqlConnector"));
     }
     if (_mysqlInsert._noneParameterFlag == "c")
     {
         _mysqlInsert._noneParameterFlag = "cu";
     }
 }
Beispiel #28
0
 public OdbcMySqlOnDuplicateKeyUpdate(IInsert <T1> insert)
 {
     _mysqlInsert = insert as OdbcMySqlInsert <T1>;
     if (_mysqlInsert == null)
     {
         throw new Exception("OnDuplicateKeyUpdate 是 FreeSql.Provider.Odbc/MySql 特有的功能");
     }
     if (_mysqlInsert._noneParameterFlag == "c")
     {
         _mysqlInsert._noneParameterFlag = "cu";
     }
 }
Beispiel #29
0
 public OdbcMySqlOnDuplicateKeyUpdate(IInsert <T1> insert)
 {
     _mysqlInsert = insert as OdbcMySqlInsert <T1>;
     if (_mysqlInsert == null)
     {
         throw new Exception(CoreStrings.S_Features_Unique("OnDuplicateKeyUpdate", "Odbc/MySql"));
     }
     if (_mysqlInsert._noneParameterFlag == "c")
     {
         _mysqlInsert._noneParameterFlag = "cu";
     }
 }
Beispiel #30
0
        /// <summary>
        /// Try to insert an element in this input.
        /// </summary>
        /// <param name="data">Reference to insertable object information</param>
        /// <returns>
        /// <para>
        /// A <see cref="InsertResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b>
        /// property will be <b>true</b> and the <b>Result</b> property will contain the Result; Otherwise, the the <b>Success</b> property
        /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in.
        /// </para>
        /// <para>
        /// The type of the return Result is <see cref="InsertResultData"/>, which contains the operation result
        /// </para>
        /// </returns>
        public InsertResult Insert(IInsert data)
        {
            Logger.Instance.Debug("");
            Logger.Instance.Debug(" Assembly: iTin.Utilities.Pdf, Namespace: iTin.Utilities.Pdf.ComponentModel, Class: PdfInput");
            Logger.Instance.Debug(" Try to replace an element in this input");
            Logger.Instance.Debug($" > Signature: ({typeof(bool)}) Replace({typeof(IInsert)}, out {typeof(NativeIO.Stream)})");
            Logger.Instance.Debug($"   > data: {data}");

            InsertResult result = InsertImplStrategy(data, this);

            if (AutoUpdateChanges)
            {
                Input = result.Result.OutputStream;
            }

            Logger.Instance.Debug($" > Output: Inserted = {result.Success}");

            return(result);
        }