Closed fdsmax closed 4 years ago
Hi, sorry I mistakenly closed this defect because of red-herring while testing the above query. I have thought the quotes in the query caused an issue. However, without quotes too the nullpointer exception is thrown from ExecuteNonQuery:
DROP TABLE IF EXISTS myschema.TableName;
If I remove 'IF EXISTS' from the query then it works ok. I think this is a defect. Therefore, I have reopened it. Pl let me know if you could re-produce the problem.
@diwakarpp Hi ive tried to reproduce this problem. Ive created a small snippet and it worked without problems.
using Npgsql;
using Npgsql.CrateDb;
namespace Sample.CrateDb.CrateDropTable
{
class Program
{
static void Main(string[] args)
{
NpgsqlDatabaseInfo.RegisterFactory(new CrateDbDatabaseInfoFactory());
//Try dropping not existing table
using (var con = OpenConnection())
using (var cmd = new NpgsqlCommand("DROP TABLE IF EXISTS myschema.abcdefg;", con))
{
var r = cmd.ExecuteNonQuery();
}
//Create Table and drop
CreateTestTable();
using (var con = OpenConnection())
using (var cmd = new NpgsqlCommand("DROP TABLE IF EXISTS myschema.TableName;", con))
{
var r = cmd.ExecuteNonQuery();
}
//Create Table and drop with quotes
CreateTestTable();
using (var con = OpenConnection())
using (var cmd = new NpgsqlCommand("DROP TABLE IF EXISTS myschema.\"tablename\";", con))
{
var r = cmd.ExecuteNonQuery();
}
}
const string DefaultConnectionString = "Server=localhost;User ID=crate;Database=npgsql_tests;Timeout=0;Command Timeout=0;Port=5435";
private static NpgsqlConnection OpenConnection(string connectionString = null)
{
if (connectionString == null)
connectionString = DefaultConnectionString;
var conn = new NpgsqlConnection(connectionString);
conn.Open();
return conn;
}
private static void CreateTestTable()
{
using (var con = OpenConnection())
{
using (var cmd = con.CreateCommand())
{
cmd.CommandText = @"create table if not exists myschema.tablename(
id integer primary key,
string_field string,
boolean_field boolean,
byte_field byte,
short_field short,
integer_field integer,
long_field long,
float_field float,
double_field double,
timestamp_field timestamp,
object_field object(strict) as (""inner"" string),
ip_field ip,
geo_point_field geo_point,
geo_shape_field geo_shape
) clustered by (id) into 1 shards with (number_of_replicas=0, column_policy = 'dynamic')";
cmd.ExecuteNonQuery();
}
}
}
}
}
Can you please check if this snippet is running for you? if not can you please provide a code snippet.
Thanks and regards, Marc
Based on the error
Npgsql.PostgresException (0x80004005): XX000: NullPointerException in io.crate.analyze.AbstractDropTableAnalyzedStatement.tableIdent(AbstractDropTableAnalyzedStatement.java:48)
I think this was a bug in CrateDB itself and not in the npgsql client. 3.2.6.
is quite old and I couldn't reproduce the NPE with current versions so I'm going to close this for now.
Hi,
The ExecteNonQuery throws NullPointerException for the below query. Any solutions or pointers to fix this?
DROP TABLE IF EXISTS myschema."TableName";
Npgsql.PostgresException (0x80004005): XX000: NullPointerException in io.crate.analyze.AbstractDropTableAnalyzedStatement.tableIdent(AbstractDropTableAnalyzedStatement.java:48) at Npgsql.NpgsqlConnector.<>cDisplayClass161_0.<gReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlConnector.<>cDisplayClass161_0.<g ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask`1.get_Result()
at Npgsql.NpgsqlDataReader.d46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.d 100.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.d__92.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
I am using nuget packages: Npgsql.CrateDb 1.2.3 net462 Npgsql.CrateFork 1.0.1 net462
Against latest crate db 3.2.6.
Thanks and regards, Diwakar