Revision: 148
Author: carlosga_fb
Date: 2006-05-19 02:22:07 -0700 (Fri, 19 May 2006)
ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=148&view=rev
Log Message:
-----------
Modified Paths:
--------------
trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgCommandBuilder.cs
Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgCommandBuilder.cs
===================================================================
--- trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgCommandBuilder.cs 2006-05-19 08:36:12 UTC (rev 147)
+++ trunk/PostgreSqlClient/source/PostgreSql/Data/PostgreSqlClient/PgCommandBuilder.cs 2006-05-19 09:22:07 UTC (rev 148)
@@ -18,6 +18,7 @@
using System;
using System.Data;
using System.Data.Common;
+using System.Globalization;
using System.Text;
using System.ComponentModel;
@@ -32,6 +33,92 @@
/// <include file='Doc/en_EN/FbCommandBuilder.xml' path='doc/class[@name="FbCommandBuilder"]/method[@name="DeriveParameters(PgCommand)"]/*'/>
public static void DeriveParameters(PgCommand command)
{
+ if (command.CommandType != CommandType.StoredProcedure)
+ {
+ throw new InvalidOperationException("The command text is not a valid stored procedure name.");
+ }
+
+ string originalSpName = command.CommandText.Trim();
+ string schemaName = "";
+ string spName = "";
+ string quotePrefix = "\"";
+ string quoteSuffix = "\"";
+
+ if (originalSpName.Contains("."))
+ {
+ string[] parts = originalSpName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
+
+ if (parts.Length > 2)
+ {
+ throw new InvalidOperationException("The command stored procedure name is not valid.");
+ }
+
+ schemaName = parts[0];
+ spName = parts[1];
+ }
+ else
+ {
+ spName = originalSpName;
+ }
+
+ if (schemaName.StartsWith(quotePrefix) && schemaName.EndsWith(quoteSuffix))
+ {
+ schemaName = schemaName.Substring(1, spName.Length - 2);
+ }
+ else
+ {
+ schemaName = schemaName.ToUpper(CultureInfo.CurrentUICulture);
+ }
+
+ if (spName.StartsWith(quotePrefix) && spName.EndsWith(quoteSuffix))
+ {
+ spName = spName.Substring(1, spName.Length - 2);
+ }
+ else
+ {
+ spName = spName.ToUpper(CultureInfo.CurrentUICulture);
+ }
+
+ string paramsText = String.Empty;
+
+ command.Parameters.Clear();
+
+ DataView dataTypes = command.Connection.GetSchema("DataTypes").DefaultView;
+
+ DataTable spSchema = command.Connection.GetSchema(
+ "FunctionParameters", new string[] { null, schemaName, spName });
+
+ int count = 1;
+ foreach (DataRow row in spSchema.Rows)
+ {
+ dataTypes.RowFilter = String.Format(
+ CultureInfo.CurrentUICulture,
+ "TypeName = '{0}'",
+ row["PARAMETER_DATA_TYPE"]);
+
+ PgParameter parameter = command.Parameters.Add(
+ "@" + row["PARAMETER_NAME"].ToString().Trim(),
+ PgDbType.VarChar);
+
+ parameter.PgDbType = (PgDbType)dataTypes[0]["ProviderDbType"];
+ parameter.Direction = (ParameterDirection)row["PARAMETER_DIRECTION"];
+ parameter.Size = Convert.ToInt32(row["PARAMETER_SIZE"], CultureInfo.InvariantCulture);
+
+ if (parameter.PgDbType == PgDbType.Decimal ||
+ parameter.PgDbType == PgDbType.Numeric)
+ {
+ if (row["NUMERIC_PRECISION"] != DBNull.Value)
+ {
+ parameter.Precision = Convert.ToByte(row["NUMERIC_PRECISION"], CultureInfo.InvariantCulture);
+ }
+ if (row["NUMERIC_SCALE"] != DBNull.Value)
+ {
+ parameter.Scale = Convert.ToByte(row["NUMERIC_SCALE"], CultureInfo.InvariantCulture);
+ }
+ }
+
+ count++;
+ }
}
#endregion
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|