Neo

Cannot use SQL TEXT fields

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1.1
  • Fix Version/s: 1.5.0
  • Component/s: Core
  • Labels:
    None
  • Number of attachments :
    1

Description

(Received by email)

I've recently come across problems inserting/updating SQL TEXT fields into a SQL Server database. SQL Server does not allow the use of '=' to compare TEXT fields and so WriteOptimisticLockMatch() will fail.

Up until recently, I didn't understand what WriteOptimisticLockMatch() was trying to achieve - it's just making sure it only operates on rows/tuples that haven't changed since local modifications have been made.

My fix to get this working was to use 'LIKE' instead of '=' for string types - there is no distinction within NEO between SQL TEXT and SQL VARCHAR as far as I can tell. For this to work, the values passed to the SQL must be escaped to remove any special characters (this is very SQL Server specific, I imagine). This operation is carried out using an overloaded version of GetParameter() which escapes string values depending upon the value of the escapeValue flag, and a new method called EscapeLikeCharacters().

This fix seems to be working well. I'm sure there's a slight performance overhead using LIKE instead of =, and there may be a few subtle bugs introduced (I think LIKE is case insensitive so text changes of just capitalisation may be ignored).

I've attached my changes which may be of interest.

Many thanks

Simon

Issue Links

Activity

Hide
Erik Doernenburg added a comment -

(received by email)

Just a quick update on the SQL TEXT and NTEXT:

I couldn't get the WriteOptimisticLockMatch() to work with text fields. I found the update matched nothing and so updates failed. My solution is to exclude TEXT fields from the optimistic write lock - not ideal, but it works.

Since I could find no obvious way to determine whether a field is of type TEXT or NTEXT, I've resorted to naming such fields as *_ntext and *_text and using two protected methods, IsSqlDbTypeText() and IsSqlDbTypeNText(), to check their type. Again, not ideal but it seems to work. The only alternative I can think of is to query the database and find out the datatypes from the server. This would be extra overhead for each update operation unless some caching was used.

Cheers
Simon

Show
Erik Doernenburg added a comment - (received by email) Just a quick update on the SQL TEXT and NTEXT: I couldn't get the WriteOptimisticLockMatch() to work with text fields. I found the update matched nothing and so updates failed. My solution is to exclude TEXT fields from the optimistic write lock - not ideal, but it works. Since I could find no obvious way to determine whether a field is of type TEXT or NTEXT, I've resorted to naming such fields as *_ntext and *_text and using two protected methods, IsSqlDbTypeText() and IsSqlDbTypeNText(), to check their type. Again, not ideal but it seems to work. The only alternative I can think of is to query the database and find out the datatypes from the server. This would be extra overhead for each update operation unless some caching was used. Cheers Simon
Hide
Casper added a comment -

Hi
I just ran in to the exact same problem, I was wondering if the solution could be to somehow store information from the Norque file (Varchar > 8000 = TEXT) in the entitymap.columns, when generating the Entity objects, then you wouldn't have to query the database later on, when deciding to use '=' or like, DataColumn.ExtendedProperties.Add("TypeInfo", "TEXT"); could be used. Just an idea........

Br
Casper

Show
Casper added a comment - Hi I just ran in to the exact same problem, I was wondering if the solution could be to somehow store information from the Norque file (Varchar > 8000 = TEXT) in the entitymap.columns, when generating the Entity objects, then you wouldn't have to query the database later on, when deciding to use '=' or like, DataColumn.ExtendedProperties.Add("TypeInfo", "TEXT"); could be used. Just an idea........ Br Casper
Hide
Erik Doernenburg added a comment -

A simple version of what you describe is already in DbDataStore, if a bit hidden. (The tutorial has a section on custom meta data that explains this.) For the next version (1.4.0) we'll add more ovious support for alternative locking strategies.

Show
Erik Doernenburg added a comment - A simple version of what you describe is already in DbDataStore, if a bit hidden. (The tutorial has a section on custom meta data that explains this.) For the next version (1.4.0) we'll add more ovious support for alternative locking strategies.
Hide
Michael Dubakov added a comment -

So what is the best way to workaround this problem in v 1.4?
Can you provide code sample?

Best
Michael

Show
Michael Dubakov added a comment - So what is the best way to workaround this problem in v 1.4? Can you provide code sample? Best Michael

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated: