Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

SQLRef ( FieldRef ; Option )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.2  (32 votes)
  Discuss this Custom Function

Phillip Caulkins, Caulkins Consulting
http://I don't have a URL to post

Makes it possible to refer indirectly to field and table occurrence names in SQL queries

Sample Input:
SQLRef ( GetFieldName ( TO::field ) ; 1 )
SQLRef ( GetFieldName ( TO::field ) ; 2 )
SQLRef ( GetFieldName ( TO::field ) ; 3 )
Sample Output:
"TO"
"field"
"TO"."field"


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

A key problem with ExecuteSQL queries as that you end up with field and table occurrence names quoted in a literal string. If you then rename a field or table occurrence, the query syntax becomes incorrect and you get the infamous ? result.

This function enables your Query to indirectly refer to field and table occurrence names such that renaming a field or table occurrence does not produce an error in a Query that refers to that object.

Example: ExecuteSQL ( "SELECT " & SQLRef ( GetFieldName ( Table::_pkID ) ; 2 ) & " FROM " & SQLRef ( GetFieldName ( Table::_pkID ) ; 1 ) ; "" ; ¶ )

Evaluates the same as:
ExecuteSQL ( "SELECT \"_pkID\" FROM \"Table\" ; "" ; ¶ )

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 6 comments

But doesn't putting the GFN inside the function mean that you have to pass the field parameter as quoted text? That would seem to defeat the purpose of this custom function--to avoid explicitly naming a field reference as quoted text so that future name changes to a table occurrence or field do not cause the query to fail.

Phillip Caulkins, Modesto, CA
August 18, 2014 10:31am

No, Phillip. Mike's right. See a similar function by Koji.
https://www.briandunning.com/cf/1476

I created something similar to Koji's then I revised mine to use your passing of other parameters:

/*
fn_convertfield_2SQL ( _field ; _q )
beverlyvoth
*/

If ( not IsEmpty ( _field )

; Let(
[ _fullnm = GetFieldName ( _field )
; _list = Substitute ( _fullnm ; "::" ; Char(13) )
; _tabl = GetValue ( _list ; 1 )
; _fld = GetValue ( _list ; 2 )

//; _sqlnm = If ( _q = 1 ; Quote(_tabl) & "." & Quote(_fld) ; _tabl & "." & _fld ) // disabled to use case for more options

; _sqlnm = Case
( _q = "qt" ; Quote(_tabl)
; _q = "qf" ; Quote(_fld)
; _q = "t" ; _tabl
; _q = "f" ; _fld
; _q = "qtqf" ; Quote(_tabl) & "." & Quote(_fld)
; _tabl & "." & _fld // default (other values or empty passed as param)
)

]; Substitute ( _sqlnm ; Char(34) ; Char(92) & Char(34) )
) // function to return escape-quoted or plain text for SQL from FM fields

; "" ) // end if

Beverly, KY
August 21, 2015 3:38am

More testing. I think with un-related fields the GFN() needs to be *outside* the call, as Phil stated. back to the drawing board...

Beverly, KY
September 03, 2015 9:52am

Not to quibble, but change the comment to read

Depending on value selected in Option returns TO name, quoted field name, or "TO.Field" text

That way it's in a 1, 2, 3 rather than a 2, 1, 3 order. I often forget what parameters mean about half a year after I write a CF, so comments are helpful.

Bill, Longmont
October 27, 2015 11:14am

Agreed, Bill! that's why I was trying to come up with "sensible" values to pass, such as qt, qf, t, f, qtqf or "". :)

beverly, KY
November 03, 2015 7:22am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 6 + 9 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions