Error with PgSqlParameter

Error with PgSqlParameter

Postby Daiser » 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)?

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( );
        }
    }
}


Output:
Connection successfull
DbType = `Int32`, PgSqlType = `Int`
ERROR: relation "19959" does not exist
DbType = `AnsiString`, PgSqlType = `Text`
Daiser
 
Posts: 4
Joined: Sat 11 Oct 2008 10:53

Postby Shalex » Tue 14 Oct 2008 09:09

We are investigating this problem. You will be notified on the results as soon as possible.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Postby Shalex » Tue 14 Oct 2008 13:45

Please replace this line from your code
Code: Select all
PgSqlCommand cmd = new PgSqlCommand( "select pg_relation_size(:par_oid)", conn );

with the following
Code: Select all
PgSqlCommand cmd = new PgSqlCommand("select pg_relation_size(CAST(:par_oid as oid))", conn);


If the problem persists, let us know.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Postby Daiser » Wed 15 Oct 2008 05:29

Thanks!
Daiser
 
Posts: 4
Joined: Sat 11 Oct 2008 10:53


Return to dotConnect for PostgreSQL