[pgsqlclient-checkins] pgsqlclient/PostgreSql.Data.PGSqlClient/source PGCommandBuilder.cs,1.1.1.1,1.
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source
In directory sc8-pr-cvs1:/tmp/cvs-serv32603
Modified Files:
PGCommandBuilder.cs PGDataReader.cs PGDbType.cs PGParameter.cs
Log Message:
* source/PGCommandBuilder.cs:
- Fixed casing in private methods and visibility level.
* source/PGDataReader.cs:
* source/PGDbType.cs:
* source/PGParameter.cs:
* source/NPGClient/PGType.cs:
- Added better andling of datatypes.
Index: PGCommandBuilder.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/PGCommandBuilder.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PGCommandBuilder.cs 12 Jul 2003 08:11:21 -0000 1.1.1.1
--- PGCommandBuilder.cs 14 Jul 2003 10:28:49 -0000 1.2
***************
*** 63,67 ****
if (dataAdapter != null)
{
! dataAdapter.RowUpdating += new PGRowUpdatingEventHandler (RowUpdatingHandler);
}
}
--- 63,67 ----
if (dataAdapter != null)
{
! dataAdapter.RowUpdating += new PGRowUpdatingEventHandler(rowUpdatingHandler);
}
}
***************
*** 96,100 ****
}
! private PGCommand SelectCommand
{
get
--- 96,100 ----
}
! private PGCommand selectCommand
{
get
***************
*** 192,197 ****
if (insertCommand == null)
{
! BuildSchemaTable();
! BuildInsertCommand(null, null);
}
--- 192,197 ----
if (insertCommand == null)
{
! buildSchemaTable();
! buildInsertCommand(null, null);
}
***************
*** 203,208 ****
if (updateCommand == null)
{
! BuildSchemaTable();
! BuildUpdateCommand(null, null);
}
--- 203,208 ----
if (updateCommand == null)
{
! buildSchemaTable();
! buildUpdateCommand(null, null);
}
***************
*** 214,219 ****
if (deleteCommand == null)
{
! BuildSchemaTable();
! BuildDeleteCommand(null, null);
}
--- 214,219 ----
if (deleteCommand == null)
{
! buildSchemaTable();
! buildDeleteCommand(null, null);
}
***************
*** 233,237 ****
#region BUILD_COMMAND_METHODS
! private PGCommand BuildInsertCommand(DataRow row, DataTableMapping tableMapping)
{
StringBuilder sql = new StringBuilder();
--- 233,237 ----
#region BUILD_COMMAND_METHODS
! private PGCommand buildInsertCommand(DataRow row, DataTableMapping tableMapping)
{
StringBuilder sql = new StringBuilder();
***************
*** 240,249 ****
string dsColumnName = String.Empty;
! insertCommand = new PGCommand(sql.ToString(), SelectCommand.Connection, SelectCommand.Transaction);
int i = 0;
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (IsUpdatable(schemaRow, row))
{
if (fields.Length > 0)
--- 240,249 ----
string dsColumnName = String.Empty;
! insertCommand = new PGCommand(sql.ToString(), selectCommand.Connection, selectCommand.Transaction);
int i = 0;
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (isUpdatable(schemaRow, row))
{
if (fields.Length > 0)
***************
*** 262,266 ****
values.Append("@param_" + i.ToString());
! PGParameter parameter = CreateParameter(schemaRow, i, false);
if (tableMapping != null)
--- 262,266 ----
values.Append("@param_" + i.ToString());
! PGParameter parameter = createParameter(schemaRow, i, false);
if (tableMapping != null)
***************
*** 301,305 ****
}
! public PGCommand BuildUpdateCommand(DataRow row, DataTableMapping tableMapping)
{
StringBuilder sql = new StringBuilder();
--- 301,305 ----
}
! private PGCommand buildUpdateCommand(DataRow row, DataTableMapping tableMapping)
{
StringBuilder sql = new StringBuilder();
***************
*** 310,322 ****
if (!hasPrimaryKey && !hasUniqueKey)
{
! throw new InvalidOperationException ("Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.");
}
! updateCommand = new PGCommand(sql.ToString(), SelectCommand.Connection, SelectCommand.Transaction);
int i = 0;
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (IsUpdatable(schemaRow, row))
{
if (sets.Length > 0)
--- 310,322 ----
if (!hasPrimaryKey && !hasUniqueKey)
{
! throw new InvalidOperationException("Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.");
}
! updateCommand = new PGCommand(sql.ToString(), selectCommand.Connection, selectCommand.Transaction);
int i = 0;
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (isUpdatable(schemaRow, row))
{
if (sets.Length > 0)
***************
*** 330,334 ****
"@param_" + i.ToString());
! PGParameter parameter = CreateParameter(schemaRow, i, false);
if (tableMapping != null)
--- 330,334 ----
"@param_" + i.ToString());
! PGParameter parameter = createParameter(schemaRow, i, false);
if (tableMapping != null)
***************
*** 362,366 ****
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (IncludedInWhereClause (schemaRow))
{
if (where.Length > 0)
--- 362,366 ----
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (includedInWhereClause (schemaRow))
{
if (where.Length > 0)
***************
*** 373,377 ****
"@param_" + i.ToString());
! PGParameter parameter = CreateParameter(schemaRow, i, true);
if (tableMapping != null)
--- 373,377 ----
"@param_" + i.ToString());
! PGParameter parameter = createParameter(schemaRow, i, true);
if (tableMapping != null)
***************
*** 412,416 ****
}
! public PGCommand BuildDeleteCommand(DataRow row, DataTableMapping tableMapping)
{
StringBuilder sql = new StringBuilder();
--- 412,416 ----
}
! private PGCommand buildDeleteCommand(DataRow row, DataTableMapping tableMapping)
{
StringBuilder sql = new StringBuilder();
***************
*** 420,427 ****
if (!hasPrimaryKey && !hasUniqueKey)
{
! throw new InvalidOperationException ("Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.");
}
! deleteCommand = new PGCommand(sql.ToString(), SelectCommand.Connection, SelectCommand.Transaction);
// Build where clausule
--- 420,427 ----
if (!hasPrimaryKey && !hasUniqueKey)
{
! throw new InvalidOperationException("Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.");
}
! deleteCommand = new PGCommand(sql.ToString(), selectCommand.Connection, selectCommand.Transaction);
// Build where clausule
***************
*** 429,433 ****
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (IncludedInWhereClause (schemaRow))
{
if (where.Length > 0)
--- 429,433 ----
foreach (DataRow schemaRow in schemaTable.Rows)
{
! if (includedInWhereClause(schemaRow))
{
if (where.Length > 0)
***************
*** 440,444 ****
"@param_" + i.ToString());
! PGParameter parameter = CreateParameter(schemaRow, i, true);
if (tableMapping != null)
--- 440,444 ----
"@param_" + i.ToString());
! PGParameter parameter = createParameter(schemaRow, i, true);
if (tableMapping != null)
***************
*** 479,485 ****
}
! private PGParameter CreateParameter(DataRow schemaRow, int index, bool isWhereParameter)
{
! PGParameter parameter = new PGParameter(String.Format("@p{0}", index), (PGType)schemaRow["ProviderType"]);
parameter.Size = Convert.ToInt32(schemaRow["ColumnSize"]);
--- 479,485 ----
}
! private PGParameter createParameter(DataRow schemaRow, int index, bool isWhereParameter)
{
! PGParameter parameter = new PGParameter(String.Format("@p{0}", index), (PGDbType)schemaRow["ProviderType"]);
parameter.Size = Convert.ToInt32(schemaRow["ColumnSize"]);
***************
*** 506,510 ****
}
! private bool IsUpdatable(DataRow schemaRow, DataRow row)
{
if (row != null)
--- 506,510 ----
}
! private bool isUpdatable(DataRow schemaRow, DataRow row)
{
if (row != null)
***************
*** 550,554 ****
}
! private bool IncludedInWhereClause(DataRow schemaRow)
{
if (!(bool)schemaRow["IsKey"])
--- 550,554 ----
}
! private bool includedInWhereClause(DataRow schemaRow)
{
if (!(bool)schemaRow["IsKey"])
***************
*** 565,590 ****
}
! private void BuildSchemaTable()
{
! if (SelectCommand == null)
{
throw new InvalidOperationException("The DataAdapter.SelectCommand property needs to be initialized.");
}
! if (SelectCommand.Connection == null)
{
! throw new InvalidOperationException ("The DataAdapter.SelectCommand.Connection property needs to be initialized.");
}
if (schemaTable == null)
{
! PGDataReader reader = SelectCommand.ExecuteReader(CommandBehavior.SchemaOnly);
schemaTable = reader.GetSchemaTable();
reader.Close();
! CheckSchemaTable();
}
}
! private void CheckSchemaTable()
{
tableName = String.Empty;
--- 565,590 ----
}
! private void buildSchemaTable()
{
! if (selectCommand == null)
{
throw new InvalidOperationException("The DataAdapter.SelectCommand property needs to be initialized.");
}
! if (selectCommand.Connection == null)
{
! throw new InvalidOperationException("The DataAdapter.selectCommand.Connection property needs to be initialized.");
}
if (schemaTable == null)
{
! PGDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SchemaOnly);
schemaTable = reader.GetSchemaTable();
reader.Close();
! checkSchemaTable();
}
}
! private void checkSchemaTable()
{
tableName = String.Empty;
***************
*** 623,627 ****
#region EVENT_HANDLER
! private void RowUpdatingHandler (object sender, PGRowUpdatingEventArgs e)
{
if (e.Status != UpdateStatus.Continue)
--- 623,627 ----
#region EVENT_HANDLER
! private void rowUpdatingHandler(object sender, PGRowUpdatingEventArgs e)
{
if (e.Status != UpdateStatus.Continue)
***************
*** 650,669 ****
try
{
! BuildSchemaTable();
switch (e.StatementType)
{
case StatementType.Insert:
! e.Command = BuildInsertCommand(e.Row, e.TableMapping);
e.Status = UpdateStatus.Continue;
break;
case StatementType.Update:
! e.Command = BuildUpdateCommand(e.Row, e.TableMapping);
e.Status = UpdateStatus.Continue;
break;
case StatementType.Delete:
! e.Command = BuildDeleteCommand(e.Row, e.TableMapping);
e.Status = UpdateStatus.Continue;
break;
--- 650,669 ----
try
{
! buildSchemaTable();
switch (e.StatementType)
{
case StatementType.Insert:
! e.Command = buildInsertCommand(e.Row, e.TableMapping);
e.Status = UpdateStatus.Continue;
break;
case StatementType.Update:
! e.Command = buildUpdateCommand(e.Row, e.TableMapping);
e.Status = UpdateStatus.Continue;
break;
case StatementType.Delete:
! e.Command = buildDeleteCommand(e.Row, e.TableMapping);
e.Status = UpdateStatus.Continue;
break;
Index: PGDataReader.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/PGDataReader.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PGDataReader.cs 13 Jul 2003 13:41:25 -0000 1.3
--- PGDataReader.cs 14 Jul 2003 10:28:49 -0000 1.4
***************
*** 622,628 ****
}
! private int getProviderType(int i)
{
! return command.Statement.RowDescriptor.Fields[i].DataType.Oid;
}
--- 622,628 ----
}
! private PGDbType getProviderType(int i)
{
! return command.Statement.RowDescriptor.Fields[i].DataType.ProviderType;
}
Index: PGDbType.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/PGDbType.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PGDbType.cs 12 Jul 2003 08:11:21 -0000 1.1.1.1
--- PGDbType.cs 14 Jul 2003 10:28:49 -0000 1.2
***************
*** 36,40 ****
Int4 ,
Int8 ,
- LongVarBinary ,
Numeric ,
Text ,
--- 36,39 ----
Index: PGParameter.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/PGParameter.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PGParameter.cs 12 Jul 2003 08:11:21 -0000 1.1.1.1
--- PGParameter.cs 14 Jul 2003 10:28:49 -0000 1.2
***************
*** 79,84 ****
public DbType DbType
{
! get { return PGTypeToDbType(pgType); }
! set { pgType = DbTypeToPGType(value); }
}
--- 79,84 ----
public DbType DbType
{
! get { return pgTypeToDbType(pgType); }
! set { pgType = dbTypeToPGType(value); }
}
***************
*** 118,126 ****
{
pValue = value;
! if (pValue == null || Convert.IsDBNull(pValue))
! {
! throw new ArgumentException("Type infering from null or DBNull is not supported.", "paramValue");
! }
! pgType = GetPGTypeFromValue(pValue);
}
}
--- 118,122 ----
{
pValue = value;
! setPGTypeFromValue(pValue);
}
}
***************
*** 188,231 ****
#region PRIVATE_METHODS
! private PGDbType GetPGTypeFromValue(object value)
{
switch (Type.GetTypeCode(value.GetType()))
{
case TypeCode.Byte:
! return PGDbType.Byte;
case TypeCode.Boolean:
! return PGDbType.Boolean;
case TypeCode.Object:
! return PGDbType.Binary;
case TypeCode.String:
case TypeCode.Char:
! return PGDbType.Char;
case TypeCode.Int16:
! return PGDbType.Int2;
case TypeCode.Int32:
! return PGDbType.Int4;
case TypeCode.Int64:
! return PGDbType.Int8;
case TypeCode.Single:
! return PGDbType.Float;
case TypeCode.Double:
! return PGDbType.Double;
case TypeCode.Decimal:
! return PGDbType.Decimal;
case TypeCode.DateTime:
! return PGDbType.TimeStamp;
case TypeCode.Empty:
- case TypeCode.DBNull:
case TypeCode.SByte:
case TypeCode.UInt16:
--- 184,240 ----
#region PRIVATE_METHODS
! private void setPGTypeFromValue(object value)
{
switch (Type.GetTypeCode(value.GetType()))
{
case TypeCode.Byte:
! pgType = PGDbType.Byte;
! break;
case TypeCode.Boolean:
! pgType = PGDbType.Boolean;
! break;
case TypeCode.Object:
! pgType = PGDbType.Binary;
! break;
case TypeCode.String:
case TypeCode.Char:
! pgType = PGDbType.Char;
! break;
case TypeCode.Int16:
! pgType = PGDbType.Int2;
! break;
case TypeCode.Int32:
! pgType = PGDbType.Int4;
! break;
case TypeCode.Int64:
! pgType = PGDbType.Int8;
! break;
case TypeCode.Single:
! pgType = PGDbType.Float;
! break;
case TypeCode.Double:
! pgType = PGDbType.Double;
! break;
case TypeCode.Decimal:
! pgType = PGDbType.Decimal;
! break;
case TypeCode.DateTime:
! pgType = PGDbType.TimeStamp;
! break;
!
! case TypeCode.DBNull:
! break;
case TypeCode.Empty:
case TypeCode.SByte:
case TypeCode.UInt16:
***************
*** 237,241 ****
}
! private DbType PGTypeToDbType(PGDbType pgType)
{
switch(pgType)
--- 246,250 ----
}
! private DbType pgTypeToDbType(PGDbType pgType)
{
switch(pgType)
***************
*** 248,252 ****
case PGDbType.Binary:
- case PGDbType.LongVarBinary:
return DbType.Binary;
--- 257,260 ----
***************
*** 288,300 ****
}
}
! private PGDbType DbTypeToPGType(DbType dbType)
{
switch(dbType)
{
- case DbType.Guid:
- case DbType.VarNumeric:
- case DbType.SByte:
- throw new SystemException("Invalid data type");
-
case DbType.Byte:
return PGDbType.Byte;
--- 296,304 ----
}
}
!
! private PGDbType dbTypeToPGType(DbType dbType)
{
switch(dbType)
{
case DbType.Byte:
return PGDbType.Byte;
***************
*** 345,348 ****
--- 349,358 ----
return PGDbType.Double;
+ case DbType.Currency:
+ return PGDbType.Currency;
+
+ case DbType.Guid:
+ case DbType.VarNumeric:
+ case DbType.SByte:
default:
throw new InvalidOperationException("Invalid data type specified.");
|