當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。