diff --git a/net/TdRules/Java.Sql/DriverManager.cs b/net/TdRules/Java.Sql/DriverManager.cs
index 3c12562..602bef9 100644
--- a/net/TdRules/Java.Sql/DriverManager.cs
+++ b/net/TdRules/Java.Sql/DriverManager.cs
@@ -1,5 +1,4 @@
using System.Data.Common;
-using System.Data.SqlClient;
namespace Java.Sql
{
@@ -14,12 +13,12 @@ public static Connection GetConnection(string url, string user, string password)
{
DbConnection nativeConn;
if (url.ToLower().StartsWith("server"))
- nativeConn = new SqlConnection(url
+ nativeConn = new System.Data.SqlClient.SqlConnection(url
+ (string.IsNullOrEmpty(user) ? "" : ";UID=" + user)
+ (string.IsNullOrEmpty(password) ? "" : ";PWD=" + password)
+ ";MultipleActiveResultSets=true");
else if (url.ToLower().StartsWith("data source"))
- nativeConn = new Microsoft.Data.Sqlite.SqliteConnection(url);
+ nativeConn = SqliteConnectionFactory.GetDbConnection(url);
else
throw new SQLException("Unrecognized connection string, it should start with 'Server' (SqlServer) or 'Data Source' (Sqlite), but was " + url);
nativeConn.Open();
diff --git a/net/TdRules/Java.Sql/ResultSet.N.cs b/net/TdRules/Java.Sql/ResultSet.N.cs
index ceab1bd..36f95de 100644
--- a/net/TdRules/Java.Sql/ResultSet.N.cs
+++ b/net/TdRules/Java.Sql/ResultSet.N.cs
@@ -102,35 +102,28 @@ public int GetInt(string field)
object Value=GetCellValue(field);
if (this.LastFieldWasNull)
return 0;
- return (int)Value;
+ return Convert.ToInt32(Value);
}
public int GetInt(int col)
{
object Value = GetCellValue(col);
if (this.LastFieldWasNull)
return 0;
- return (int)Value;
+ return Convert.ToInt32(Value);
}
- public long GetLong(int col)
- {
- object Value = GetCellValue(col);
- if (this.LastFieldWasNull)
- return 0;
- return (long)Value;
- }
- public short GetShort(string field)
+ public long GetLong(string field)
{
object Value = GetCellValue(field);
if (this.LastFieldWasNull)
return 0;
- return short.Parse(Value.ToString()); //no permite cast short
+ return Convert.ToInt64(Value);
}
- public short GetShort(int col)
+ public long GetLong(int col)
{
object Value = GetCellValue(col);
if (this.LastFieldWasNull)
return 0;
- return short.Parse(Value.ToString());
+ return Convert.ToInt64(Value);
}
public bool GetBoolean(string field)
{
diff --git a/net/TdRules/Java.Sql/SqliteConnection.N.cs b/net/TdRules/Java.Sql/SqliteConnection.N.cs
deleted file mode 100644
index 71f2a44..0000000
--- a/net/TdRules/Java.Sql/SqliteConnection.N.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-//This is part of CORE.Net, don't edit outside this solution
-namespace Java.Sql
-{
- internal class SqliteConnection
- {
- }
-}
\ No newline at end of file
diff --git a/net/TdRules/Java.Sql/SqliteConnectionFactory.N.cs b/net/TdRules/Java.Sql/SqliteConnectionFactory.N.cs
new file mode 100644
index 0000000..0be9e11
--- /dev/null
+++ b/net/TdRules/Java.Sql/SqliteConnectionFactory.N.cs
@@ -0,0 +1,13 @@
+//This is part of CORE.Net, don't edit outside this solution
+using System.Data.Common;
+
+namespace Java.Sql
+{
+ internal class SqliteConnectionFactory
+ {
+ public static DbConnection GetDbConnection(string url)
+ {
+ return new Microsoft.Data.Sqlite.SqliteConnection(url);
+ }
+ }
+}
\ No newline at end of file
diff --git a/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb.Sqlite/TestSqliteResultSet.cs b/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb.Sqlite/TestSqliteResultSet.cs
new file mode 100644
index 0000000..14caa6d
--- /dev/null
+++ b/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb.Sqlite/TestSqliteResultSet.cs
@@ -0,0 +1,16 @@
+/////////////////////////////////////////////////////////////////////////////////////////////
+/////// THIS FILE HAS BEEN AUTOMATICALLY CONVERTED FROM THE JAVA SOURCES. DO NOT EDIT ///////
+/////////////////////////////////////////////////////////////////////////////////////////////
+using Sharpen;
+using Test4giis.Tdrules.Store.Rdb;
+
+namespace Test4giis.Tdrules.Store.Rdb.Sqlite
+{
+ public class TestSqliteResultSet : TestSqlserverResultSet
+ {
+ public TestSqliteResultSet()
+ {
+ this.dbmsname = "sqlite";
+ }
+ }
+}
diff --git a/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverResultSet.cs b/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverResultSet.cs
new file mode 100644
index 0000000..2d3afca
--- /dev/null
+++ b/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverResultSet.cs
@@ -0,0 +1,118 @@
+/////////////////////////////////////////////////////////////////////////////////////////////
+/////// THIS FILE HAS BEEN AUTOMATICALLY CONVERTED FROM THE JAVA SOURCES. DO NOT EDIT ///////
+/////////////////////////////////////////////////////////////////////////////////////////////
+using System;
+using Giis.Portable.Util;
+using Java.Sql;
+using NUnit.Framework;
+using Sharpen;
+
+namespace Test4giis.Tdrules.Store.Rdb
+{
+ /// Reading basic data types from a ResultSet, check nullability and access by name or column number.
+ ///
+ /// Reading basic data types from a ResultSet, check nullability and access by name or column number.
+ /// Intended to test the .net ResultSet wrapper implementation
+ ///
+ public class TestSqlserverResultSet : Base
+ {
+ protected internal Connection dbt;
+
+ protected internal ResultSet rs;
+
+ protected internal string sCreate1 = "create table tabrs1 (pk integer primary key not null, " + "tint integer, tchar varchar(16), tdate date, tlong bigint)";
+
+ protected internal string sSelect1 = "select pk, tint, tchar, tdate, tlong from tabrs1";
+
+ ///
+ [NUnit.Framework.SetUp]
+ public override void SetUp()
+ {
+ base.SetUp();
+ dbt = GetConnection(TestDbname2);
+ ExecuteNotThrow(dbt, "drop table tabrs1");
+ Execute(dbt, sCreate1);
+ }
+
+ ///
+ [NUnit.Framework.TearDown]
+ public virtual void TearDown()
+ {
+ if (rs != null)
+ {
+ rs.Close();
+ }
+ dbt.Close();
+ }
+
+ ///
+ [Test]
+ public virtual void TestReadResultSet()
+ {
+ Execute(dbt, "insert into tabrs1 (pk,tint,tchar,tdate,tlong) values(1, 2, null, '2023-01-02', null)");
+ Execute(dbt, "insert into tabrs1 (pk,tint,tchar,tdate,tlong) values(2, null, 'chrchr', null, 55)");
+ // 1st round: even columns are not null/odd columns are null (except pk),
+ // read by column number
+ rs = Query(dbt, sSelect1);
+ NUnit.Framework.Legacy.ClassicAssert.IsTrue(rs.Next());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(1, rs.GetInt(1));
+ int tint = rs.GetInt(2);
+ NUnit.Framework.Legacy.ClassicAssert.IsFalse(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(2, tint);
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual("2", rs.GetString(2));
+ string tchar = rs.GetString(3);
+ NUnit.Framework.Legacy.ClassicAssert.IsTrue(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(null, tchar);
+ DateTime tdate;
+ if (!"sqlite".Equals(dbmsname))
+ {
+ // sqlite does not have native Date
+ tdate = rs.GetDate(4);
+ NUnit.Framework.Legacy.ClassicAssert.IsFalse(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual("2023-01-02", DateString(tdate));
+ // normalize Date for .net compatibility
+ NUnit.Framework.Legacy.ClassicAssert.IsNotNull(rs.GetString(4));
+ }
+ // do not check value because is system/locale dependent
+ long tlong = rs.GetLong(5);
+ NUnit.Framework.Legacy.ClassicAssert.IsTrue(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(0, tlong);
+ // 2nd round: alternate nullability, read by column name
+ NUnit.Framework.Legacy.ClassicAssert.IsTrue(rs.Next());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(2, rs.GetInt("pk"));
+ tint = rs.GetInt("tint");
+ NUnit.Framework.Legacy.ClassicAssert.IsTrue(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(0, tint);
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(null, rs.GetString("tint"));
+ tchar = rs.GetString("tchar");
+ NUnit.Framework.Legacy.ClassicAssert.IsFalse(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual("chrchr", tchar);
+ if (!"sqlite".Equals(dbmsname))
+ {
+ tdate = rs.GetDate("tdate");
+ NUnit.Framework.Legacy.ClassicAssert.IsTrue(rs.WasNull());
+ if ("java".Equals(Platform))
+ {
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(null, tdate);
+ }
+ else
+ {
+ // on .net, DateTime is no nullable, returns DateTime.MinValue
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual("0001-01-01", DateString(tdate));
+ }
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(null, rs.GetString("tdate"));
+ }
+ tlong = rs.GetLong("tlong");
+ NUnit.Framework.Legacy.ClassicAssert.IsFalse(rs.WasNull());
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual(55, tlong);
+ NUnit.Framework.Legacy.ClassicAssert.AreEqual("55", rs.GetString("tlong"));
+ // resultset end
+ NUnit.Framework.Legacy.ClassicAssert.IsFalse(rs.Next());
+ }
+
+ private string DateString(DateTime dt)
+ {
+ return JavaCs.Substring(JavaCs.GetIsoDate(dt), 0, 10);
+ }
+ }
+}
diff --git a/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverSchemaMetadata.cs b/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverSchemaMetadata.cs
index 84352e9..a4306a9 100644
--- a/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverSchemaMetadata.cs
+++ b/net/TdRulesTest/Translated/Test4giis.Tdrules.Store.Rdb/TestSqlserverSchemaMetadata.cs
@@ -173,7 +173,7 @@ protected internal virtual void AssertMetadata(string metadata, string fileName)
FileUtil.FileWrite(TestPathOutput, fileName, metadata);
string expected = FileUtil.FileRead(TestPathBenchmark, fileName);
VisualAssert va = new VisualAssert();
- va.AssertEquals(expected, metadata);
+ va.AssertEquals(expected.Replace("\r", string.Empty), metadata.Replace("\r", string.Empty));
}
/// List de tablas y/o vistas, discriminado por tipo
diff --git a/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverResultSet.java b/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverResultSet.java
new file mode 100644
index 0000000..05a1ca8
--- /dev/null
+++ b/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverResultSet.java
@@ -0,0 +1,113 @@
+package test4giis.tdrules.store.rdb;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import giis.portable.util.JavaCs;
+
+/**
+ * Reading basic data types from a ResultSet, check nullability and access by name or column number.
+ * Intended to test the .net ResultSet wrapper implementation
+ */
+public class TestSqlserverResultSet extends Base {
+ protected Connection dbt;
+ protected ResultSet rs;
+
+ protected String sCreate1 = "create table tabrs1 (pk integer primary key not null, "
+ + "tint integer, tchar varchar(16), tdate date, tlong bigint)";
+ protected String sSelect1 = "select pk, tint, tchar, tdate, tlong from tabrs1";
+
+ @Before
+ public void setUp() throws SQLException {
+ super.setUp();
+ dbt = getConnection(TEST_DBNAME2);
+ executeNotThrow(dbt, "drop table tabrs1");
+ execute(dbt, sCreate1);
+ }
+
+ @After
+ public void tearDown() throws SQLException {
+ if (rs != null)
+ rs.close();
+ dbt.close();
+ }
+
+ @Test
+ public void testReadResultSet() throws SQLException {
+ execute(dbt, "insert into tabrs1 (pk,tint,tchar,tdate,tlong) values(1, 2, null, '2023-01-02', null)");
+ execute(dbt, "insert into tabrs1 (pk,tint,tchar,tdate,tlong) values(2, null, 'chrchr', null, 55)");
+
+ // 1st round: even columns are not null/odd columns are null (except pk),
+ // read by column number
+ rs = query(dbt, sSelect1);
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+
+ int tint = rs.getInt(2);
+ assertFalse(rs.wasNull());
+ assertEquals(2, tint);
+ assertEquals("2", rs.getString(2));
+
+ String tchar = rs.getString(3);
+ assertTrue(rs.wasNull());
+ assertEquals(null, tchar);
+
+ Date tdate;
+ if (!"sqlite".equals(dbmsname)) { // sqlite does not have native Date
+ tdate = rs.getDate(4);
+ assertFalse(rs.wasNull());
+ assertEquals("2023-01-02", dateString(tdate)); // normalize Date for .net compatibility
+ assertNotNull(rs.getString(4)); // do not check value because is system/locale dependent
+ }
+
+ long tlong = rs.getLong(5);
+ assertTrue(rs.wasNull());
+ assertEquals(0, tlong);
+
+ // 2nd round: alternate nullability, read by column name
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt("pk"));
+
+ tint = rs.getInt("tint");
+ assertTrue(rs.wasNull());
+ assertEquals(0, tint);
+ assertEquals(null, rs.getString("tint"));
+
+ tchar = rs.getString("tchar");
+ assertFalse(rs.wasNull());
+ assertEquals("chrchr", tchar);
+
+ if (!"sqlite".equals(dbmsname)) {
+ tdate = rs.getDate("tdate");
+ assertTrue(rs.wasNull());
+ if ("java".equals(PLATFORM))
+ assertEquals(null, tdate);
+ else // on .net, DateTime is no nullable, returns DateTime.MinValue
+ assertEquals("0001-01-01", dateString(tdate));
+ assertEquals(null, rs.getString("tdate"));
+ }
+
+ tlong = rs.getLong("tlong");
+ assertFalse(rs.wasNull());
+ assertEquals(55, tlong);
+ assertEquals("55", rs.getString("tlong"));
+
+ // resultset end
+ assertFalse(rs.next());
+ }
+
+ private String dateString(Date dt) {
+ return JavaCs.substring(JavaCs.getIsoDate(dt), 0, 10);
+ }
+}
diff --git a/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverSchemaMetadata.java b/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverSchemaMetadata.java
index 3d492f5..4df7f47 100644
--- a/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverSchemaMetadata.java
+++ b/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/TestSqlserverSchemaMetadata.java
@@ -156,7 +156,7 @@ protected void assertMetadata(String metadata, String fileName) {
FileUtil.fileWrite(TEST_PATH_OUTPUT, fileName, metadata);
String expected = FileUtil.fileRead(TEST_PATH_BENCHMARK, fileName);
VisualAssert va = new VisualAssert().setFramework(Framework.JUNIT4);
- va.assertEquals(expected, metadata);
+ va.assertEquals(expected.replace("\r", ""), metadata.replace("\r", ""));
}
/**
diff --git a/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/sqlite/TestSqliteResultSet.java b/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/sqlite/TestSqliteResultSet.java
new file mode 100644
index 0000000..dc3bc77
--- /dev/null
+++ b/tdrules-store-rdb/src/test/java/test4giis/tdrules/store/rdb/sqlite/TestSqliteResultSet.java
@@ -0,0 +1,11 @@
+package test4giis.tdrules.store.rdb.sqlite;
+
+import test4giis.tdrules.store.rdb.TestSqlserverResultSet;
+
+public class TestSqliteResultSet extends TestSqlserverResultSet {
+
+ public TestSqliteResultSet() {
+ this.dbmsname = "sqlite";
+ }
+
+}