Skip to content

Commit 47f1f34

Browse files
author
Christian Junk
committed
Fixed problem with case sensitive replacement.
1 parent dbc1ab9 commit 47f1f34

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/NHibernate.JetDriver/JetDialect.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Data;
34
using System.Data.Common;
5+
using System.Data.OleDb;
6+
using System.Text.RegularExpressions;
47
using NHibernate.Dialect.Function;
58
using NHibernate.Dialect.Schema;
69
using NHibernate.JetDriver.Schema;
@@ -212,9 +215,9 @@ public override bool SupportsVariableLimit
212215
/// <returns>Processed query</returns>
213216
public override SqlString GetLimitString(SqlString queryString, SqlString offset, SqlString limit)
214217
{
215-
// int insertIndex = GetAfterSelectInsertPoint(queryString);
216-
//
217-
// var builder = new SqlStringBuilder(queryString);
218+
// int insertIndex = GetAfterSelectInsertPoint(queryString);
219+
//
220+
// var builder = new SqlStringBuilder(queryString);
218221

219222
/*
220223
* Where 15 is the StartPos + PageSize, and 5 is the PageSize. https://stackoverflow.com/a/1900668/100863
@@ -233,9 +236,18 @@ ORDER BY subOrdered.`SMP_GLOBALID`
233236
builder.
234237
*/
235238

236-
var lim = limit.ToString();
237-
var result = queryString.Replace("SELECT", string.Format("SELECT TOP {0}", limit));
238-
return result;
239+
// var returnList = new List<string>();
240+
//
241+
// DataTable dt = _jetDbConnection.Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, new Object[] { null, null, "Employee" });
242+
// int columnOrdinalForName = dt.Columns["COLUMN_NAME"].Ordinal;
243+
//
244+
// foreach (DataRow r in dt.Rows)
245+
// {
246+
// returnList.Add(r.ItemArray[columnOrdinalForName].ToString());
247+
// }
248+
249+
var result = Regex.Replace(queryString.ToString(), "SELECT", $"SELECT TOP {limit}", RegexOptions.IgnoreCase);
250+
return new SqlString(result);
239251
}
240252

241253

@@ -268,10 +280,11 @@ public override string UnQuote(string quoted)
268280
return quoted.Replace(new string(CloseQuote, 2), CloseQuote.ToString());
269281
}
270282

283+
private JetDbConnection _jetDbConnection;
271284
public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
272285
{
273-
var jetConnection = (JetDbConnection)connection;
274-
return new JetDataBaseSchema(jetConnection.Connection);
286+
_jetDbConnection = (JetDbConnection)connection;
287+
return new JetDataBaseSchema(_jetDbConnection.Connection);
275288
}
276289

277290
public override JoinFragment CreateOuterJoinFragment()

0 commit comments

Comments
 (0)