当前位置: 首页>>代码示例>>C#>>正文


C# NpgsqlCommand.?.Dispose方法代码示例

本文整理汇总了C#中Npgsql.NpgsqlCommand.?.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlCommand.?.Dispose方法的具体用法?C# NpgsqlCommand.?.Dispose怎么用?C# NpgsqlCommand.?.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npgsql.NpgsqlCommand的用法示例。


在下文中一共展示了NpgsqlCommand.?.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteSql

        /// <summary>
        ///     Executes a SQL statement.
        ///     WARNING: only use for program-generated SQL statements. Statements
        ///     which include user input should be executed using prepared
        ///     statements to avoid possible injection attacks.
        /// </summary>
        /// <param name="sqlStmt">The SQL statement to execute</param>
        /// <param name="conn">The open connection object to the database</param>
        internal static int ExecuteSql(string sqlStmt, NpgsqlConnection conn)
        {
            NpgsqlCommand cmd = null;

            try
            {
                cmd = new NpgsqlCommand(sqlStmt, conn);
                return cmd.ExecuteNonQuery();
            }
            catch (NpgsqlException ex)
            {
                Log.Write('E', ' ', sqlStmt);
                Log.WriteEx('E', Constants.LogTsType, ex);
                return -1;
            }
            finally {
                cmd?.Dispose();
            }
        }
开发者ID:mvrolijk,项目名称:ConvertPG2SS,代码行数:27,代码来源:Postgres.cs

示例2: CreateImportFile

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="schema"></param>
        /// <param name="table"></param>
        /// <param name="conn"></param>
        private static int CreateImportFile(
			this TextWriter sw,
			string schema,
			string table,
			NpgsqlConnection conn)
        {
            var limit = int.Parse(_params[Parameters.PostgresLimit].ToString());
            string sql;

            if (limit > 0)
            {
                sql = string.Format(
                    CultureInfo.InvariantCulture,
                    "SELECT * FROM \"{0}\".\"{1}\" LIMIT {2}",
                    schema, table, limit);
            }
            else
            {
                sql = string.Format(
                    CultureInfo.InvariantCulture,
                    "SELECT * FROM \"{0}\".\"{1}\"",
                    schema, table);
            }

            var criteria = string.Format(
                CultureInfo.InvariantCulture,
                "schema_name = '{0}' AND table_name = '{1}'",
                schema, table);

            var tblDict = ((Dictionary<string, DataTable>) _params[Constants.PgTables]);
            var dt = tblDict[Constants.PgSchemaTable];
            NpgsqlCommand cmd = null;
            NpgsqlDataReader reader = null;
            var colInfo = dt.Select(criteria, "column_index");
            var recCount = 0;

            try
            {
                cmd = new NpgsqlCommand(sql, conn);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    sw.WriteLine(ProcessRow(reader, colInfo));
                    recCount++;
                    //if (recCount%100000 == 0) {
                    //	sw.Flush();
                    //	_log.Write('T', Constants.LogTsType, recCount.ToString("N0"), 2);
                    //}
                }
            }
            catch (NpgsqlException ex) {
                _log.WriteEx('F', Constants.LogTsType, ex);
                throw;
            }
            finally
            {
                reader?.Dispose();
                cmd?.Dispose();
            }

            var pad = (49 - schema.Length - table.Length);
            string qualName;

            if (pad > 0) qualName = schema + "." + table + new string('.', pad);
            else qualName = schema + "." + table;

            _log.Write(
                'I',
                Constants.LogTsType,
                string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}: {1,13:n0}",
                    qualName, recCount),
                1);

            return recCount;
        }
开发者ID:mvrolijk,项目名称:ConvertPG2SS,代码行数:85,代码来源:ProcessPgBulk.cs


注:本文中的Npgsql.NpgsqlCommand.?.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。