Creating a new function for SQLServer

Skip to first unread message

Tom Robinson

Aug 18, 2019, 10:23:57 PM8/18/19
to glorp-group

Does anyone have experience adding functions to Glorp.  I find myself needing to use the following expression in a query: right(version, length(version), - patindex("%0.%", version). Right now, I'm trying to implement #right: as a PrefixFunction by adding it to SQLServerPlatform>>#initializeFunctions using the following code:

    functions at: #right: put: ((PrefixFunction named: 'RIGHT') type: (self varchar: 255)).

My test code looks like this:

     | session query results |
     session := StoreLoginFactory currentStoreSession.
     query := Query read: Store.Glorp.StorePackage
          where: [:ea| (ea version right: 5) = '57540'].
     results := session execute: query.

The result is an error: Unhandled exception: Invalid data type. It appears that the Query is trying to convert the argument 5 to the varchar type to be returned. This is happening in the processing of binding, before any attempt is made to generate SQL. Is there a way to specify an argument type or is that something that needs to be added? Is there something simple that I'm doing wrong?



Wallen, David

Aug 23, 2019, 4:28:57 PM8/23/19

Hi Tom,


Sorry, I was away all week. Your function seems to work. However, I get an empty list for results—perhaps the record isn’t in my repository.

Here’s what I tried:

1. Add Tom’s new function in method, SQLServerPlatform>>initializeFunctions.

2. Connect to the SQL 2012 repository (which sends SQLServerPlatform new initializeFunctions).

3. Inspect the workspace code


Here is the query it generates.

SELECT  TOP 1 t1.identityName

FROM NEWBERN2.BERN.TW_DatabaseIdentifier t1  OrderedCollection ()

(0.594 s)

SELECT t1.primaryKey,, t1.timeStamp, t1.version, t1.userName, t1.trace, t1.blessingLevel, t1.commentID, t1.propertiesID, t1.binFile, t1.parcelID


WHERE (RIGHT(t1.version,5) = :1)  OrderedCollection ('57540')

(0.016 s)


Dave Wallen 
Software Engineer




This e-mail transmission contains information that is intended to be privileged and confidential. It is intended only for the addressee named above. If you receive this e-mail in error, please do not read, copy or disseminate it in any manner. If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this information is prohibited, please reply to the message immediately by informing the sender that the message was misdirected. After replying, please erase it from your computer system. Your assistance in correcting this error is appreciated.

You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Reply all
Reply to author
0 new messages