Error with PgSqlParameter
Posted: Sat 11 Oct 2008 11:46
I'm trying to get pg_relation_size() for table using OID (19959). Query ends with exception "relation "19959" does not exist". It means that PostgreSQL executes pg_relation_size(text) instead of pg_relation_size(oid). Why PgSqlCommand.ExecuteScalar() transforms PgSqlParameter from Int32(Int) to AnsiString(Text)?
Output:
Connection successfull
DbType = `Int32`, PgSqlType = `Int`
ERROR: relation "19959" does not exist
DbType = `AnsiString`, PgSqlType = `Text`
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
using CoreLab.PostgreSql;
namespace pgdFailure2 {
class Program {
static void Main( string[ ] args ) {
PgSqlConnection conn = new PgSqlConnection( );
conn.Database = "*****";
conn.Host = "sql";
conn.Port = 5432;
conn.UserId = "*****";
conn.Password = "*****";
conn.Unicode = true;
conn.Open( );
Console.WriteLine( "Connection successfull" );
PgSqlCommand cmd = new PgSqlCommand( "select pg_relation_size(:par_oid)", conn );
cmd.Parameters.Add( "par_oid", 19959 );
Console.WriteLine( "DbType = `{0}`, PgSqlType = `{1}`",
cmd.Parameters[ 0 ].DbType.ToString( ),
cmd.Parameters[ 0 ].PgSqlType.ToString( ) );
try {
object result = cmd.ExecuteScalar( );
Console.WriteLine( result.ToString( ) );
} catch( PgSqlException e ) {
Console.WriteLine( "ERROR: {0}", e.Message );
}
Console.WriteLine( "DbType = `{0}`, PgSqlType = `{1}`",
cmd.Parameters[ 0 ].DbType.ToString( ),
cmd.Parameters[ 0 ].PgSqlType.ToString( ) );
conn.Close( );
Console.ReadLine( );
}
}
}
Connection successfull
DbType = `Int32`, PgSqlType = `Int`
ERROR: relation "19959" does not exist
DbType = `AnsiString`, PgSqlType = `Text`