Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Figueiredo Jr. <fxjr@mono-cvs.ximian.com>2004-11-25 18:19:55 +0300
committerFrancisco Figueiredo Jr. <fxjr@mono-cvs.ximian.com>2004-11-25 18:19:55 +0300
commit4d190daa2f456d6923cc20195640dcb048ee333d (patch)
tree9d3c4cd8907da9e3503029751a0e35855998314d /mcs/class/Npgsql/NpgsqlTypes
parent14486abb7f7bd0bf86150d10ec63ace4e28ea3cb (diff)
2004-11-25 Francisco Figueiredo Jr. <fxjrlists@yahoo.com.br>
Update to 0.7beta3 release. * NpgsqlBind.cs: Minor code cleanup. * NpgsqlClosedState.cs: Code formatting. * NpgsqlCommand.cs: Code cleanup and updating for new Plan and Portal name generation code. * NpgsqlConnection.cs: Fixed contructor log message. * NpgsqlConnectionString.cs: Code formatting. * NpgsqlConnector.cs: ReleasePlansPortals: Added method to release used plans and portals. NextPortalName, NextPlanName: Added methods to handle name generation. * NpgsqlConnectorPool.cs: UngetPooledConnector: Added call to release plans and portals in connector. * NpgsqlError.cs: New constructor which takes ProtocolVersion and String parameters. * NpgsqlQuery.cs: Changed constructor to take an NpgsqlCommand instead of just the command string. * NpgsqlReadyState.cs: Changed code to reflect NpgsqlQuery change. * NpgsqlState.cs: ProcessBackendResponses_Ver_(2,3): Fixed handling of invalid authentication methods. Thanks Magnus Hagander (mha at sollentuna dot net) for the heads up. * NpgsqlState.resx: Fixed resource key typo. * NpgsqlTransaction.cs: Fixed IDisposable pattern implementation of NpgsqlTransaction. Now it doesn't incorrectly raise InvalidOperation exceptions. Thanks Ivan Radovanovic ( rivan at sezampro dot yu ) for heads up. * NpgsqlDbType.cs: Code cleanup. * NpgsqlTypeConverters.cs : Removed method to handle string. String quoting is handled prevously as it depends in the type of query: simple or extended. * NpgsqlTypes.cs: Code cleanup. * NpgsqlTypesHelper.cs: (CreateAndLoadInitialTypesMapping): Removed delegate handler of String types. It's not necessary anymore. (ConvertToBackend): Refactorying. Fixed gborg 1035. Thanks Magnus Hagander (mha at sollentuna dot net) for the heads up. svn path=/trunk/mcs/; revision=36553
Diffstat (limited to 'mcs/class/Npgsql/NpgsqlTypes')
-rw-r--r--mcs/class/Npgsql/NpgsqlTypes/NpgsqlDbType.cs57
-rw-r--r--mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypeConverters.cs8
-rw-r--r--mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypes.cs198
-rwxr-xr-xmcs/class/Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs87
4 files changed, 198 insertions, 152 deletions
diff --git a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlDbType.cs b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlDbType.cs
index 7b16600170d..fd77761808d 100644
--- a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlDbType.cs
+++ b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlDbType.cs
@@ -1,5 +1,5 @@
// NpgsqlTypes.NpgsqlDbType.cs
-//
+//
// Author:
// Francisco Jr. (fxjrlists@yahoo.com.br)
//
@@ -11,12 +11,12 @@
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
-//
+//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
-//
+//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -26,29 +26,30 @@ using Npgsql;
namespace NpgsqlTypes
{
- public enum NpgsqlDbType
- {
- Bigint,
- Boolean,
- Box,
- Bytea,
- Circle,
- Date,
- Double,
- Integer,
- Line,
- LSeg,
- Money,
- Numeric,
- Path,
- Point,
- Polygon,
- Real,
- Smallint,
- Text,
- Time,
- Timestamp
-
- }
-
+ public enum NpgsqlDbType
+ {
+ Bigint,
+ Boolean,
+ Box,
+ Bytea,
+ Circle,
+ Date,
+ Double,
+ Integer,
+ Interval,
+ Line,
+ LSeg,
+ Money,
+ Numeric,
+ Path,
+ Point,
+ Polygon,
+ Real,
+ Smallint,
+ Text,
+ Time,
+ Timestamp
+
+ }
+
}
diff --git a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypeConverters.cs b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypeConverters.cs
index e3cd77baed3..38bd9c146b0 100644
--- a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypeConverters.cs
+++ b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypeConverters.cs
@@ -190,14 +190,6 @@ namespace NpgsqlTypes
internal abstract class BasicNativeToBackendTypeConverter
{
/// <summary>
- /// String data.
- /// </summary>
- internal static String ToString(NpgsqlNativeTypeInfo TypeInfo, Object NativeData)
- {
- return NativeData.ToString().Replace("'", "''").Replace("\\", "\\\\");
- }
-
- /// <summary>
/// Binary data.
/// </summary>
internal static String ToBinary(NpgsqlNativeTypeInfo TypeInfo, Object NativeData)
diff --git a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypes.cs b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypes.cs
index db57d90ac1f..7c727853091 100644
--- a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypes.cs
+++ b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypes.cs
@@ -37,88 +37,88 @@ using System.Drawing;
namespace NpgsqlTypes
{
- /// <summary>
- /// Represents a PostgreSQL Point type
- /// </summary>
-
- public struct NpgsqlPoint
- {
- private Single _X;
- private Single _Y;
-
- public NpgsqlPoint(Single X, Single Y)
- {
- _X = X;
- _Y = Y;
- }
-
- public Single X
- {
- get
- {
- return _X;
- }
-
- set
- {
- _X = value;
- }
- }
-
-
- public Single Y
- {
- get
- {
- return _Y;
- }
-
- set
- {
- _Y = value;
- }
- }
- }
-
- public struct NpgsqlBox
- {
- private NpgsqlPoint _UpperRight;
- private NpgsqlPoint _LowerLeft;
-
- public NpgsqlBox(NpgsqlPoint UpperRight, NpgsqlPoint LowerLeft)
- {
- _UpperRight = UpperRight;
- _LowerLeft = LowerLeft;
- }
-
-
- public NpgsqlPoint UpperRight
- {
- get
- {
- return _UpperRight;
- }
- set
- {
- _UpperRight = value;
- }
- }
-
- public NpgsqlPoint LowerLeft
- {
- get
- {
- return _LowerLeft;
- }
- set
- {
- _LowerLeft = value;
- }
- }
-
- }
-
-
+ /// <summary>
+ /// Represents a PostgreSQL Point type
+ /// </summary>
+
+ public struct NpgsqlPoint
+ {
+ private Single _X;
+ private Single _Y;
+
+ public NpgsqlPoint(Single X, Single Y)
+ {
+ _X = X;
+ _Y = Y;
+ }
+
+ public Single X
+ {
+ get
+ {
+ return _X;
+ }
+
+ set
+ {
+ _X = value;
+ }
+ }
+
+
+ public Single Y
+ {
+ get
+ {
+ return _Y;
+ }
+
+ set
+ {
+ _Y = value;
+ }
+ }
+ }
+
+ public struct NpgsqlBox
+ {
+ private NpgsqlPoint _UpperRight;
+ private NpgsqlPoint _LowerLeft;
+
+ public NpgsqlBox(NpgsqlPoint UpperRight, NpgsqlPoint LowerLeft)
+ {
+ _UpperRight = UpperRight;
+ _LowerLeft = LowerLeft;
+ }
+
+
+ public NpgsqlPoint UpperRight
+ {
+ get
+ {
+ return _UpperRight;
+ }
+ set
+ {
+ _UpperRight = value;
+ }
+ }
+
+ public NpgsqlPoint LowerLeft
+ {
+ get
+ {
+ return _LowerLeft;
+ }
+ set
+ {
+ _LowerLeft = value;
+ }
+ }
+
+ }
+
+
/// <summary>
/// Represents a PostgreSQL Line Segment type.
/// </summary>
@@ -145,8 +145,8 @@ namespace NpgsqlTypes
public struct NpgsqlPath
{
internal NpgsqlPoint[] Points;
-
- internal Boolean IsOpen;
+
+ internal Boolean IsOpen;
public NpgsqlPath(NpgsqlPoint[] Points)
{
@@ -155,17 +155,23 @@ namespace NpgsqlTypes
}
public Int32 Count
- { get { return Points.Length; } }
+ { get
+ {
+ return Points.Length;
+ } }
public NpgsqlPoint this [Int32 Index]
- { get { return Points[Index]; } }
-
+ { get
+ {
+ return Points[Index];
+ } }
+
public Boolean Open
{
- get
- {
- return IsOpen;
- }
+ get
+ {
+ return IsOpen;
+ }
}
}
@@ -182,10 +188,16 @@ namespace NpgsqlTypes
}
public Int32 Count
- { get { return Points.Length; } }
+ { get
+ {
+ return Points.Length;
+ } }
public NpgsqlPoint this [Int32 Index]
- { get { return Points[Index]; } }
+ { get
+ {
+ return Points[Index];
+ } }
}
/// <summary>
diff --git a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs
index 63e9ff49bfe..b62ebb4a04f 100755
--- a/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs
+++ b/mcs/class/Npgsql/NpgsqlTypes/NpgsqlTypesHelper.cs
@@ -160,8 +160,7 @@ namespace NpgsqlTypes
NativeTypeMapping = new NpgsqlNativeTypeMapping();
- NativeTypeMapping.AddType("text", NpgsqlDbType.Text, DbType.String, true,
- new ConvertNativeToBackendHandler(BasicNativeToBackendTypeConverter.ToString));
+ NativeTypeMapping.AddType("text", NpgsqlDbType.Text, DbType.String, true, null);
NativeTypeMapping.AddDbTypeAlias("text", DbType.StringFixedLength);
NativeTypeMapping.AddDbTypeAlias("text", DbType.AnsiString);
@@ -221,8 +220,13 @@ namespace NpgsqlTypes
NativeTypeMapping.AddType("timestamp", NpgsqlDbType.Timestamp, DbType.DateTime, true,
new ConvertNativeToBackendHandler(BasicNativeToBackendTypeConverter.ToDateTime));
-
+
NativeTypeMapping.AddTypeAlias("timestamp", typeof(DateTime));
+
+ NativeTypeMapping.AddType("interval", NpgsqlDbType.Interval, DbType.DateTime, true,
+ new ConvertNativeToBackendHandler(BasicNativeToBackendTypeConverter.ToDateTime));
+
+ //NativeTypeMapping.AddTypeAlias("interval", typeof(DateTime));
NativeTypeMapping.AddType("point", NpgsqlDbType.Point, DbType.Object, true,
new ConvertNativeToBackendHandler(ExtendedNativeToBackendTypeConverter.ToPoint));
@@ -349,6 +353,9 @@ namespace NpgsqlTypes
new NpgsqlBackendTypeInfo(0, "timestamp", NpgsqlDbType.Timestamp, DbType.DateTime, typeof(DateTime),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToDateTime)),
+
+ new NpgsqlBackendTypeInfo(0, "interval", NpgsqlDbType.Interval, DbType.DateTime, typeof(DateTime),
+ new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToDateTime)),
new NpgsqlBackendTypeInfo(0, "timestamptz", NpgsqlDbType.Timestamp, DbType.DateTime, typeof(DateTime),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToDateTime)),
@@ -588,32 +595,66 @@ namespace NpgsqlTypes
/// plain queries or extended queries</param>
public String ConvertToBackend(Object NativeData, Boolean ForExtendedQuery)
{
+ if (ForExtendedQuery)
+ return ConvertToBackendExtendedQuery(NativeData);
+ else
+ return ConvertToBackendPlainQuery(NativeData);
+
+ }
+
+ private String ConvertToBackendPlainQuery(Object NativeData)
+ {
if ((NativeData == DBNull.Value) || (NativeData == null))
- if (ForExtendedQuery)
- return null; // Extended query expects null values be represented as null.
- else
- return "NULL"; // Plain queries exptects null values as string NULL.
-
- else if (_ConvertNativeToBackend != null) {
- return QuoteString(! ForExtendedQuery, _ConvertNativeToBackend(this, NativeData));
+ return "NULL"; // Plain queries exptects null values as string NULL.
+
+ if (_ConvertNativeToBackend != null)
+ return QuoteString(_ConvertNativeToBackend(this, NativeData));
+ else
+ {
+
+
+ if (NativeData is System.Enum)
+ {
+ // Do a special handling of Enum values.
+ // Translate enum value to its underlying type.
+ return QuoteString((String)Convert.ChangeType(Enum.Format(NativeData.GetType(), NativeData, "d"), typeof(String), CultureInfo.InvariantCulture));
+ }
+ else
+ // Do special handling of strings when in simple query. Escape quotes and backslashes.
+
+ return QuoteString(NativeData.ToString().Replace("'", "''").Replace("\\", "\\\\"));
- } else {
- // Do a special handling of Enum values.
- // Translate enum value to its underlying type.
- if (NativeData is System.Enum)
- return QuoteString(! ForExtendedQuery, (String)Convert.ChangeType(Enum.Format(NativeData.GetType(), NativeData, "d"), typeof(String), CultureInfo.InvariantCulture));
-
- return QuoteString(! ForExtendedQuery, (String)Convert.ChangeType(NativeData, typeof(String), CultureInfo.InvariantCulture));
}
+
}
-
- private static String QuoteString(Boolean Quote, String S)
+
+ private String ConvertToBackendExtendedQuery(Object NativeData)
{
- if (Quote) {
- return String.Format("'{0}'", S);
- } else {
- return S;
+ if ((NativeData == DBNull.Value) || (NativeData == null))
+ return null; // Extended query expects null values be represented as null.
+
+ if (_ConvertNativeToBackend != null)
+ return _ConvertNativeToBackend(this, NativeData);
+ else
+ {
+ if (NativeData is System.Enum)
+ {
+ // Do a special handling of Enum values.
+ // Translate enum value to its underlying type.
+ return (String)Convert.ChangeType(Enum.Format(NativeData.GetType(), NativeData, "d"), typeof(String), CultureInfo.InvariantCulture);
+ }
+ else
+ // Do special handling of strings when in simple query. Escape quotes and backslashes.
+ return NativeData.ToString();
+
}
+
+ }
+
+ private static String QuoteString(String S)
+ {
+ return String.Format("'{0}'", S);
+
}
}