Topic: Using the escape special characters function

Is it possible to use the above function when using MVD to automatically post data to the database?

I understand how to do it with an 'on_click' procedure and manually write the SQL using SQLExecute, but can it be called somehow and still have MVD automatically add or save  a database entry?

On a clear disk you can seek forever

Re: Using the escape special characters function

Hi CDB,
I'm not sure what you mean by 'using the escape special characters function'.
What exactly is it that you're trying to do?
Derek.

Re: Using the escape special characters function

Hi Derek,

I need to be able to enter into  text boxes and a memo box things like 21.5" or "some such" . I see that Dmitry has referenced  several posts with the inbuilt (I assume) function:

SQLexecute('UPDATE some_table SET a_field = '''+escape_special_characters(mainform.editbox1.text)+'''

That of course requires writing the SQL query manually, which I know I do a lot, but just thought where I do use MVD to prepare the SQL query behind the scenes, it would be nice if this function could be accessed in some way.

Ref post: http://myvisualdatabase.com/forum/viewt … 360#p30360

On a clear disk you can seek forever

4 (edited by derek 2020-05-20 21:00:15)

Re: Using the escape special characters function

Hi CDB,
As I understand it, the 'escape special characters' function is for when you want to use quotes, double quotes etc in either insert or update statements in your script. 
I'm guessing this is for your 'parts ordering' application, so I was (idly!) wondering whether you could take a different approach and achieve the same sort of thing with a conversion table.
I've put a small app together to show the sort of thing I'm meaning (it's doing manually what you would possibly do in batch) but the principle is the same.  In my example, my 'conversion' table is heights and the different formats they may be held in.
Depending on exactly what you're trying to do, it might be totally impractical - in which case just bin it.
Derek.

Post's attachments

Attachment icon escapechars.zip 338.23 kb, 221 downloads since 2020-05-20 

Re: Using the escape special characters function

Thanks Derek,


I'm not sure that will help in this instance as it would need me to create  a list of items that might be entered beforehand which wouldn't work for the 'freehand' entries in a memo box, and, I still need to use a script.


I've just experimented with the Student  Performance  example program, it looks as though the entries are escaped by MVD.


So I need to investigate why that doesn't seem to be the case in my little program. Possibly because I've mixed MVD and script. I shall investigate.

On a clear disk you can seek forever

6 (edited by CDB 2020-05-21 01:43:58)

Re: Using the escape special characters function

The code below works for single and multiple quotes, but not for speech marks.  I can live with that.

var
s1: String;
begin

 s1 := frmMain.edtDeascription.text;
 s1 := '''' + escape_special_characters(s1) + '''';

sqlexecute('INSERT INTO productSupplier (ID,supplier_part_number,id_suppliers,id_products,description) VALUES ("'+IntToStr(dbid)+'", "'+frmMain.edtSupplierCode.text+'","'+IntToStr(suppID)+'","'+IntToStr(prodID)+'",'S1' )');
    
end;
On a clear disk you can seek forever

7 (edited by derek 2020-05-21 10:55:44)

Re: Using the escape special characters function

Hi CDB,
I was looking at your 'escape special characters' question again.
I was wondering if there is a more 'general purpose' approach by holding 'special' characters in a table (I always seem to go with the 'data driven' options - LOL!).  You'd then select the type of 'special character' from a combobox, whether it's to be inserted to the left, to the right or on both ends of  the description etc.  It should mean that you don't need to do any script maintenance once you've set it up.
Anyway, I knocked up the attached which may give you some options (again, if not, just bin it).  In my example I'm doing 'selects' rather than 'inserts' but the principle is the same, and you just choose from the combobox, the special characters you want to use.
Derek.

Post's attachments

Attachment icon escapechars2.zip 341.13 kb, 215 downloads since 2020-05-21 

Re: Using the escape special characters function

That sounds interesting, I'll take a look. Thanks

On a clear disk you can seek forever

9 (edited by derek 2020-05-21 14:52:05)

Re: Using the escape special characters function

Hi CDB,
Changed a couple of things to give more flexibility.  Now you don't need to change anything in the script - it's wholly data driven by what's in the 'escapechars' table.
You now have the option to specify a different 'left' and 'right' character for the field you want to update.
It also works with fields that already have single quotes, double quotes, speech marks etc in them (ie The King's Shilling can be changed to "The King's Shilling" etc).
Derek.

Post's attachments

Attachment icon escapechars3.zip 339.69 kb, 249 downloads since 2020-05-21