+
+2005-01-21 Francisco Figueiredo Jr. <fxjrlists@yahoo.com>
+ * NpgsqlTypes/NpgsqlDbType.cs,
+ NpgsqlTypes/NpgsqlTypesHelper.cs: Added support for Varchar datatype. Removed Internal data type enum. It is not supported yet.
+ * Npgsql/PGUtil.cs,
+ Npgsql/PGUtil.resx: (WriteString) Added support for logging what string is being written to database server.
+ * Npgsql/NpgsqlCommand.cs: Added SingleRow behavior support.
+ gborg 1099. Added support for record return type functions. Thanks neri and Michel for heads up and tests.
+ Fixed record function bug when function had many parameters. Thanks Neri (neri at gborg dot postgresql dot org) for heads up.
+ * Npgsql/NpgsqlCommandBuilder.cs,
+ NpgsqlDataAdapter.cs: Applied patch to fix gborg 1095. Thanks Eric van der Gutten (ericvdg at ananzi dot co dot za).
+ * Npgsql/NpgsqlDataReader.cs: Removed type conversions for GetXXX() methods.
+
+
+
2004-12-20 Francisco Figueiredo Jr. <fxjrlists@yahoo.com>
+ * Npgsql/NpgsqlCommand.cs: gborg 1099. Added support for record return type functions. Thanks neri and Michel for heads up and tests.
+ * Npgsql/NpgsqlDataReader.cs: Removed type conversions for GetXXX() methods.
* Npgsql/NpgsqlCommand.cs: Added IClonable implementation. Also added strong type NpgsqlTransaction property and converted previous interface implementation to implicit interface implementation. Thanks Christopher Gersbo-Møller (cgm at knowledgelab dot sdu dot dk) for heads up.
2004-12-19 Francisco Figueiredo Jr. <fxjrlists@yahoo.com>
Boolean addProcedureParenthesis = false; // Do not add procedure parenthesis by default.
+ Boolean functionReturnsRecord = false; // Functions don't return record by default.
+
String result = text;
if (type == CommandType.StoredProcedure)
{
+
+ functionReturnsRecord = CheckFunctionReturnRecord();
+
// Check if just procedure name was passed. If so, does not replace parameter names and just pass parameter values in order they were added in parameters collection.
if (!result.Trim().EndsWith(")"))
{
if (Connector.SupportsPrepare)
result = "select * from " + result; // This syntax is only available in 7.3+ as well SupportsPrepare.
else
- result = "select " + result; // Only a single result return supported. 7.2 and earlier.
+ result = "select " + result; //Only a single result return supported. 7.2 and earlier.
}
else if (type == CommandType.TableDirect)
- return "select * from " + result; // There is no parameter support on table direct.
+ return "select * from " + result; // There is no parameter support on table direct.
if (parameters == null || parameters.Count == 0)
+ {
if (addProcedureParenthesis)
- return AddSingleRowBehaviorSupport(result + ")");
- else
- return AddSingleRowBehaviorSupport(result);
+ result += ")";
+
+ if (functionReturnsRecord)
+ result = AddFunctionReturnsRecordSupport(result);
+
+
+ result = AddSingleRowBehaviorSupport(result);
+
+ return result;
+ }
//CheckParameters();
Param.TypeInfo.ConvertToBackend(Param.Value, false)
);
else
- result += Param.TypeInfo.ConvertToBackend(Param.Value, false);
+ result += Param.TypeInfo.ConvertToBackend(Param.Value, false) + ",";
}
+
if (addProcedureParenthesis)
+ {
+ // Remove a trailing comma added from parameter handling above. If any.
+ // Maybe there are only output parameters.
+ if (result.EndsWith(","))
+ result = result.Remove(result.Length - 1, 1);
+
result += ")";
+ }
+ if (functionReturnsRecord)
+ result = AddFunctionReturnsRecordSupport(result);
+
return AddSingleRowBehaviorSupport(result);
}
+
+
+
+ private Boolean CheckFunctionReturnRecord()
+ {
+
+ if (Parameters.Count == 0)
+ return false;
+
+ String returnRecordQuery = "select count(*) > 0 from pg_proc where prorettype = ( select oid from pg_type where typname = 'record' ) and proargtypes='{0}' and proname='{1}';";
+
+ StringBuilder parameterTypes = new StringBuilder("");
+
+ foreach(NpgsqlParameter p in Parameters)
+ {
+ if ((p.Direction == ParameterDirection.Input) ||
+ (p.Direction == ParameterDirection.InputOutput))
+ {
+ parameterTypes.Append(Connection.Connector.OidToNameMapping[p.TypeInfo.Name].OID + " ");
+ }
+ }
+
+
+ NpgsqlCommand c = new NpgsqlCommand(String.Format(returnRecordQuery, parameterTypes.ToString(), CommandText), Connection);
+
+ Boolean ret = (Boolean) c.ExecuteScalar();
+
+ // reset any responses just before getting new ones
+ connector.Mediator.ResetResponses();
+ return ret;
+
+
+ }
+
+
+ private String AddFunctionReturnsRecordSupport(String OriginalResult)
+ {
+
+ StringBuilder sb = new StringBuilder(OriginalResult);
+
+ sb.Append(" as (");
+
+ foreach(NpgsqlParameter p in Parameters)
+ {
+ if ((p.Direction == ParameterDirection.Output) ||
+ (p.Direction == ParameterDirection.InputOutput))
+ {
+ sb.Append(String.Format("{0} {1}, ", p.ParameterName.Substring(1), p.TypeInfo.Name));
+ }
+ }
+
+ String result = sb.ToString();
+
+ result = result.Remove(result.Length - 2, 1);
+
+ result += ")";
+
+
+
+ return result;
+
+
+ }
}//ReplaceParameterValue
- private String AddSingleRowBehaviorSupport(String resultCommandText)
+ private String AddSingleRowBehaviorSupport(String ResultCommandText)
{
+
+ ResultCommandText = ResultCommandText.Trim();
if ((commandBehavior & CommandBehavior.SingleRow) > 0)
{
- if (resultCommandText.EndsWith(";"))
- resultCommandText = resultCommandText.Substring(0, resultCommandText.Length - 1);
- resultCommandText += " limit 1;";
+ if (ResultCommandText.EndsWith(";"))
+ ResultCommandText = ResultCommandText.Substring(0, ResultCommandText.Length - 1);
+ ResultCommandText += " limit 1;";
}
- return resultCommandText;
+ return ResultCommandText;
}
using System;
using System.Data;
+using System.Data.Common;
using System.ComponentModel;
namespace Npgsql
bool disposed = false;
+
private NpgsqlDataAdapter data_adapter;
private NpgsqlCommand insert_command;
private NpgsqlCommand update_command;
public NpgsqlCommandBuilder (NpgsqlDataAdapter adapter)
{
DataAdapter = adapter;
+ adapter.RowUpdating += new NpgsqlRowUpdatingEventHandler(OnRowUpdating);
}
public NpgsqlDataAdapter DataAdapter {
}
}
+ private void OnRowUpdating(Object sender, NpgsqlRowUpdatingEventArgs value) {
+ switch (value.StatementType)
+ {
+ case StatementType.Insert:
+ value.Command = GetInsertCommand(value.Row);
+ break;
+ case StatementType.Update:
+ value.Command = GetUpdateCommand(value.Row);
+ break;
+ case StatementType.Delete:
+ value.Command = GetDeleteCommand(value.Row);
+ break;
+ }
+
+ DataColumnMappingCollection columnMappings = value.TableMapping.ColumnMappings;
+ foreach (IDataParameter parameter in value.Command.Parameters)
+ {
+
+ string dsColumnName = parameter.SourceColumn;
+ if (columnMappings.Contains(parameter.SourceColumn))
+ {
+ DataColumnMapping mapping = columnMappings[parameter.SourceColumn];
+ if (mapping != null)
+ {
+ dsColumnName = mapping.DataSetColumn;
+ }
+ }
+
+ DataRowVersion rowVersion = DataRowVersion.Default;
+ if (value.StatementType == StatementType.Update)
+ rowVersion = parameter.SourceVersion;
+ if (value.StatementType == StatementType.Delete)
+ rowVersion = DataRowVersion.Original;
+ parameter.Value = value.Row [dsColumnName, rowVersion];
+ }
+ value.Row.AcceptChanges ();
+ }
+
public string QuotePrefix {
get
{
// Npgsql.NpgsqlDataAdapter.cs
//
// Author:
-// Francisco Jr. (fxjrlists@yahoo.com.br)
+// Francisco Jr. (fxjrlists@yahoo.com.br)
//
-// Copyright (C) 2002 The Npgsql Development Team
-// npgsql-general@gborg.postgresql.org
-// http://gborg.postgresql.org/project/npgsql/projdisplay.php
+// Copyright (C) 2002 The Npgsql Development Team
+// npgsql-general@gborg.postgresql.org
+// http://gborg.postgresql.org/project/npgsql/projdisplay.php
//
//
// This library is free software; you can redistribute it and/or
public sealed class NpgsqlDataAdapter : DbDataAdapter, IDbDataAdapter
{
- private NpgsqlCommand _selectCommand;
- private NpgsqlCommand _updateCommand;
- private NpgsqlCommand _deleteCommand;
- private NpgsqlCommand _insertCommand;
-
- private NpgsqlCommandBuilder cmd_builder;
+ private NpgsqlCommand _selectCommand;
+ private NpgsqlCommand _updateCommand;
+ private NpgsqlCommand _deleteCommand;
+ private NpgsqlCommand _insertCommand;
// Log support
private static readonly String CLASSNAME = "NpgsqlDataAdapter";
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);
_selectCommand = selectCommand;
- cmd_builder = new NpgsqlCommandBuilder(this);
}
public NpgsqlDataAdapter(String selectCommandText, NpgsqlConnection selectConnection) : this(new NpgsqlCommand(selectCommandText, selectConnection))
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "OnRowUpdating");
if ((RowUpdating != null) && (value is NpgsqlRowUpdatingEventArgs))
RowUpdating(this, (NpgsqlRowUpdatingEventArgs) value);
-
- /*switch (value.StatementType)
- {
- case StatementType.Insert:
- value.Command = cmd_builder.GetInsertCommand(value.Row);
- break;
- case StatementType.Update:
- value.Command = cmd_builder.GetUpdateCommand(value.Row);
- break;
- case StatementType.Delete:
- value.Command = cmd_builder.GetDeleteCommand(value.Row);
- break;
- }
- DataColumnMappingCollection columnMappings = value.TableMapping.ColumnMappings;
- foreach (IDataParameter parameter in value.Command.Parameters)
- {
-
- string dsColumnName = parameter.SourceColumn;
- if (columnMappings.Contains(parameter.SourceColumn))
- {
- DataColumnMapping mapping = columnMappings[parameter.SourceColumn];
- if (mapping != null)
- {
- dsColumnName = mapping.DataSetColumn;
- }
- }
- DataRowVersion rowVersion = DataRowVersion.Default;
- if (value.StatementType == StatementType.Update)
- rowVersion = parameter.SourceVersion;
- if (value.StatementType == StatementType.Delete)
- rowVersion = DataRowVersion.Original;
- parameter.Value = value.Row [dsColumnName, rowVersion];
- }
- value.Row.AcceptChanges ();*/
-
}
ITableMappingCollection IDataAdapter.TableMappings
}
/// <summary>
- /// Gets the value of a column converted to a Boolean.
+ /// Gets the value of a column as Boolean.
/// </summary>
public Boolean GetBoolean(Int32 i)
{
// and parsing from there?
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetBoolean");
- return Convert.ToBoolean(GetValue(i));
+ return (Boolean) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to a Byte. Not implemented.
+ /// Gets the value of a column as Byte. Not implemented.
/// </summary>
public Byte GetByte(Int32 i)
{
}
/// <summary>
- /// Gets the value of a column converted to a Char. Not implemented.
+ /// Gets the value of a column as Char. Not implemented.
/// </summary>
public Char GetChar(Int32 i)
{
}
/// <summary>
- /// Gets the value of a column converted to Int16.
+ /// Gets the value of a column as Int16.
/// </summary>
public Int16 GetInt16(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetInt16");
- return Convert.ToInt16(GetValue(i));
+ return (Int16) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to Int32.
+ /// Gets the value of a column as Int32.
/// </summary>
public Int32 GetInt32(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetInt32");
- return Convert.ToInt32(GetValue(i));
+ return (Int32) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to Int64.
+ /// Gets the value of a column as Int64.
/// </summary>
public Int64 GetInt64(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetInt64");
- return Convert.ToInt64(GetValue(i));
+ return (Int64) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to Single.
+ /// Gets the value of a column as Single.
/// </summary>
public Single GetFloat(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetFloat");
- return Convert.ToSingle(GetValue(i));
+ return (Single) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to Double.
+ /// Gets the value of a column as Double.
/// </summary>
public Double GetDouble(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetDouble");
- return Convert.ToDouble(GetValue(i));
+ return (Double) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to a String.
+ /// Gets the value of a column as String.
/// </summary>
public String GetString(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetString");
- return Convert.ToString(GetValue(i));
+ return (String) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to Decimal.
+ /// Gets the value of a column as Decimal.
/// </summary>
public Decimal GetDecimal(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetDecimal");
- return Convert.ToDecimal(GetValue(i));
+ return (Decimal) GetValue(i);
}
/// <summary>
- /// Gets the value of a column converted to a DateTime.
+ /// Gets the value of a column as DateTime.
/// </summary>
public DateTime GetDateTime(Int32 i)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetDateTime");
- return Convert.ToDateTime(GetValue(i));
+ return (DateTime) GetValue(i);
}
/// <summary>
public static void WriteString(String the_string, Stream network_stream, Encoding encoding)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteString");
+
+ NpgsqlEventLog.LogMsg(resman, "Log_StringWritten", LogLevel.Debug, the_string);
network_stream.Write(encoding.GetBytes(the_string + '\x00') , 0, encoding.GetByteCount(the_string) + 1);
}
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
- -->\r
+ -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<data name="Log_StringRead">
<value>String read: {0}.</value>
</data>
+ <data name="Log_StringWritten">
+ <value>String written: {0}.</value>
+ </data>
</root>
Date,
Double,
Integer,
- Interval,
Line,
LSeg,
Money,
Smallint,
Text,
Time,
- Timestamp
+ Timestamp,
+ Varchar
}
NativeTypeMapping.AddDbTypeAlias("text", DbType.AnsiStringFixedLength);
NativeTypeMapping.AddTypeAlias("text", typeof(String));
+ NativeTypeMapping.AddType("varchar", NpgsqlDbType.Varchar, DbType.String, true, null);
+
NativeTypeMapping.AddType("bytea", NpgsqlDbType.Bytea, DbType.Binary, true,
new ConvertNativeToBackendHandler(BasicNativeToBackendTypeConverter.ToBinary));
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.AddTypeAlias("timestamp", typeof(DateTime));
NativeTypeMapping.AddType("point", NpgsqlDbType.Point, DbType.Object, true,
new ConvertNativeToBackendHandler(ExtendedNativeToBackendTypeConverter.ToPoint));
new NpgsqlBackendTypeInfo(0, "bpchar", NpgsqlDbType.Text, DbType.String, typeof(String),
null),
- new NpgsqlBackendTypeInfo(0, "varchar", NpgsqlDbType.Text, DbType.String, typeof(String),
+ new NpgsqlBackendTypeInfo(0, "varchar", NpgsqlDbType.Varchar, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "text", NpgsqlDbType.Text, DbType.String, typeof(String),
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)),