SQLify code from Programming Guide does not work

I am following the Xojo Introduction to programming guide specifically page 226 regarding the SQLify method.

Here is the code I wrote:

Var result As String
result = source.ReplaceAll(“'”, “’ '”)
Return result

Here is the error I get:

Window1.SQLify, line 2
This item does not exist
result = source.ReplaceAll(“'”, “’ '”)

Window1.SQLify, line 2
There is more than one method with this name but this does not match any of the available signatures.
result = source.ReplaceAll(“'”, “’ '”)

Window1.SQLify, line 2
Type mismatch error. Expected String, but got Int32
result = source.ReplaceAll(“'”, “’ '”)

None of the previous steps have shown any errors when I run the project, (well, not now anyway).

What have I missed please?

Looks like smart quotes are on, they don’t play nice with Xojo. You need to use the old school quotes “”

Ignore that, looks like it is the forum doing the conversion of the quote types

What does the declaration of the function look like? Is it using source as string?

Return type is String

“Source” does not seem to be defined or declared anywhere I can find ??

You should have defined it when you added the method. source should be in the parameters field

Name: sqlify
Parameters: source as string
Return type: string

I am following the Intro to programming guide so that needs to be fixed.

Thanks.

Thanks Tim, I can see the mechanics of what was wrong, but where does source “come from”. What functionality does it provide or inherit ?? Whatever ??

“source” comes from wherever you call sqlify from. There is a good example in the programming guide.

Put a button on the window and in the Pressed event, put

var s as string = "isn't this pleasant"
var t as string = sqlify(s)   // s becomes "source" in the sqlify method
break

Examine the contents of both s and t to see the efffects of sqlify.

Note: if you try to send s to the database, it will break. If you send t, it will succeed and the database will contain the contents of s.

Note 2: This example is ancient and out of favor. It still works, and used to be the only way to go, but the better way is to use prepared statements to send data to the database. But it’s not a bad exercise to get used to creating methods and calling them.

1 Like

@Tim_Hare Thanks. Much appreciated.

Why does Xojo’s official programming guide have a SQLify method?! This is a terrible practice. The guide should be using parameters instead.

2 Likes