Issue Details (XML | Word | Printable)

Key: NEO-5
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Erik Doernenburg
Reporter: Erik Doernenburg
Votes: 2
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Neo

Cannot use SQL TEXT fields

Created: 27/May/04 08:12 AM   Updated: 09/Mar/06 03:08 PM
Return to search
Component/s: Core
Affects Version/s: 1.1.1
Fix Version/s: 1.5.0

Time Tracking:
Not Specified

File Attachments: 1. Text File SqlDataStore.cs (30 kB)

Issue Links:
Supercedes
 


 Description  « Hide

(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



Erik Doernenburg added a comment - 27/May/04 08:15 AM

(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


Casper added a comment - 04/Aug/05 11:29 AM

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


Erik Doernenburg added a comment - 04/Aug/05 12:49 PM

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.


Michael Dubakov added a comment - 09/Mar/06 03:08 PM

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

Best
Michael