Hello.
If anybody has an experience with the creation of NHibernate driver and dialect specific to Pervasive SQL DB, please share it.
I tried for myself, but got exceptions i cannot deal with. Below i'll provide some details.
Here's my Pervasive driver implementation:
Code:
public class PervasiveClientDriver : ReflectionBasedDriver
{
public PervasiveClientDriver()
: base(
"Pervasive.Data.SqlClient",
"Pervasive.Data.SqlClient.PsqlConnection",
"Pervasive.Data.SqlClient.PsqlCommand")
{
}
public override bool UseNamedPrefixInSql
{
get { return true; }
}
public override bool UseNamedPrefixInParameter
{
get { return true; }
}
public override string NamedPrefix
{
get { return "?"; }
}
}
As a dialect i decided to use NHibernate.Dialect.MsSql2000Dialect.
Also, i configured NHibernate in this way:
Code:
Configuration cfg = new Configuration();
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2000Dialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "PervasiveSampling.PervasiveClientDriver, PervasiveSampling");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "ServerDSN=DEMODATA;UID=test;PWD=test;ServerName=localhost");
My query looks like:
Code:
IQuery query = session.CreateQuery("select p from Person as p where p.FirstName = 'James'");
At runtime i got the following exception:
Code:
2008-03-03 21:04:13,984 [232] NHibernate.Loader.Loader.GetResultSet(:0) - SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?p0
2008-03-03 21:04:13,984 [232] NHibernate.Impl.BatcherImpl.LogCommand(:0) - SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?p0; ?p0 = '104101361'
2008-03-03 21:04:14,031 [232] NHibernate.Util.ADOExceptionReporter.LogExceptions(:0) - SQL Exception
Pervasive.Data.SqlClient.PsqlException: Pervasive.Data.SqlClient.Lna.LnaException: [LNA][Pervasive][ODBC Engine Interface]Syntax Error: SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?p<< ??? >>0
at Pervasive.Data.SqlClient.Lna.LnaStatement.ExecDirect(String sql, ParamInfoSet pis, ColumnInfoSet cis, ParamDescSet pds)
at Pervasive.Data.SqlClient.PsqlCommand.Execute(Boolean parseOnly, CommandBehavior behavior, Boolean needReader)
at Pervasive.Data.SqlClient.PsqlCommand.ExecuteReader(CommandBehavior behavior)
at Pervasive.Data.SqlClient.PsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
2008-03-03 21:04:14,046 [232] NHibernate.Util.ADOExceptionReporter.LogExceptions(:0) - Pervasive.Data.SqlClient.PsqlException: Pervasive.Data.SqlClient.Lna.LnaException: [LNA][Pervasive][ODBC Engine Interface]Syntax Error: SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?p<< ??? >>0
at Pervasive.Data.SqlClient.Lna.LnaStatement.ExecDirect(String sql, ParamInfoSet pis, ColumnInfoSet cis, ParamDescSet pds)
at Pervasive.Data.SqlClient.PsqlCommand.Execute(Boolean parseOnly, CommandBehavior behavior, Boolean needReader)
at Pervasive.Data.SqlClient.PsqlCommand.ExecuteReader(CommandBehavior behavior)
at Pervasive.Data.SqlClient.PsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
Moreover, when i used the following configuration:
Code:
Configuration cfg = new Configuration();
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2000Dialect");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.OdbcDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString,
"Driver={Pervasive ODBC Client Interface};ServerDSN=DEMODATA;ServerName=localhost;UID=test;PWD=test");
everything worked just fine, and through the logs i saw this SQL has been generated:
Code:
2008-03-03 21:23:38,421 [2460] NHibernate.Impl.BatcherImpl.Generate(:0) - Building an IDbCommand object for the SqlString: SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?
2008-03-03 21:23:38,421 [2460] NHibernate.Type.NullableType.NullSafeSet(:0) - binding '104101361' to parameter: 0
2008-03-03 21:23:38,421 [2460] NHibernate.Loader.Loader.GetResultSet(:0) - SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?
2008-03-03 21:23:38,421 [2460] NHibernate.Impl.BatcherImpl.LogCommand(:0) - SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?; p0 = '104101361'
After careful revision of two SQLs we can note the difference:
Code:
SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?p0; ?p0 = '104101361'
versus
Code:
SELECT person0_.Id as Id0_0_, person0_.First_Name as First2_0_0_ FROM Person person0_ WHERE person0_.Id=?; p0 = '104101361'
Both SQLs are not processed through the Pervasive.SQL Control Center's SQL Editor.
I would be very grateful for any help.
Thanks in advance.
P.S. Sorry for long post.