Vendor session myFMbutler DoSQL 2

Preview:

DESCRIPTION

Slides from the vendor session about myFMbutler DoSQL 2 at the FileMaker Devcon 2013 in San Diego.

Citation preview

Do more with SQLin FileMaker

Koen Van Hulle

Koen Van Hulle

Gent

Niels Heyvaert - http://www.sxc.hu

Belgium

Linda DuBose

Vince Varga - http://www.sxc.hu

I work at

• FileMaker “7...12” Certified developer

• 2012 FileMaker Mad Dog PR Award

better known as

• FileMaker Hosting

• Tools and add-ons for FileMaker

FMbutlermy

our product range

the easiest way to send e-mail, text messages and faxes from FileMaker Server 12

• Checks which e-mails need to be sent, based on FileMaker field criteria

• Runs a background process

• Supports plain text as well as HTML e-mail

• Easy implementation

• Ideal for integration in

the ultimate developer tool that saves you tons of development time

• Stores complete FileMaker fields, tables, scripts, script steps and layouts in an easy-to-use library.

• Clip Editor

• Clip History

• easy access with the “snippets” feature.

allows you to easily control printer switching from within your FileMaker

• switches printers on the fly

• generates PDF in runtime solutions

• captures printer settings like page orientation, paper size etc. and restores them at the time of printing

Do more with SQL in FileMaker

• uses SQL statements to select, update, create or delete FileMaker records.

• doesn't require any drivers

• Returns native FileMaker data types like dates, images, formatted text,

• Debug tools

Menu

• FQL Engine demystified

• Overview of most common SQL commands

• Other DoSQL Commands

• Common mistakes

FQL engine?

• FileMaker code that accesses the data in another way

• Providing an alternative way of “talking” to the data

• Using multiple FQL interfaces to the database(s)

One FQL engine, four interfaces

ODBCdriver

JDBCdriver

plug-inAPI

executeSQL

Outside

ODBCdriver

JDBCdriver

plug-inAPI

executeSQL

Inside

Credentials at login Credentials of the current user

plug-inAPI

executeSQL

Inside

Credentials of the current user

Selecting a database

ExecuteSQL()

• only the file of the calculation context

Plug-in API

• any existing open file with second generation plug-ins

What does the FQL engine support?

• SQL-92

• SELECT

• DELETE

• INSERT

• UPDATE

• CREATE TABLE

• ALTER TABLE

• CREATE INDEX

• DROP INDEX

What does executeSQL support?

• SQL-92

• SELECT

• DELETE

• INSERT

• UPDATE

• CREATE TABLE

• ALTER TABLE

• CREATE INDEX

• DROP INDEX

SELECTSELECT [DISTINCT] {* | column_expression [[AS] column_alias],...}FROM table_name [table_alias], ...[ WHERE expr1 rel_operator expr2 ][ GROUP BY {column_expression, ...} ][ HAVING expr1 rel_operator expr2 ][ UNION [ALL] (SELECT...) ][ ORDER BY {sort_expression [DESC | ASC]}, ... ][ OFFSET n {ROWS | ROW} ][ FETCH FIRST [ n [ PERCENT ] ] { ROWS | ROW } {ONLY | WITH TIES } ][ FOR UPDATE [OF {column_expression, ...}] ]

SELECT

SELECT sum(salary), Name, EmpID, Department FROM Employees WHERE Department = ‘marketing’

SELECTExecuteSQL(“SELECT sum(salary), Name, EmpID, Department FROM Employees WHERE Department = ‘marketing’”; ”;” ; “¶” )

1 000 000;Willy Sommers;203;marketing1 000 000;Dana Winner;204;marketing1 000 000;Eva De Waelle;205;marketing1 000 000;Maarten Cox;206;marketing1 000 000;Danny Fabry;207;marketing

SELECTExecuteSQL(“SELECT sum(salary), Name, EmpID, Department FROM Employees WHERE Department = ?”; ”;” ; “¶” ; globals::department )

1 000 000;Willy Sommers;203;marketing1 000 000;Dana Winner;204;marketing1 000 000;Eva De Waelle;205;marketing1 000 000;Maarten Cox;206;marketing1 000 000;Danny Fabry;207;marketing

RESULT• Always TEXT

• Always one TEXT string per query

Result = TextLet(x = ExecuteSQL("SELECT sum(salary) FROM Employees WHERE Department = ?"; "" ; ""; globals::department );x < 20 000)* sum(salary) = 1 000 000

TRUE“1 000 000”< 20 000

Result = TextLet(x = ExecuteSQL("SELECT sum(salary) FROM Employees WHERE Department = ?"; "" ; ""; globals::department);GetAsNumber(x) < 20 000)* sum(salary) = 1 000 000

False1 000 000< 20 000

Result = TEXT

• Date: “2013-08-15”

• Time: “02:49:03”

• Timestamp: “2013-08-15 02:49:03”

• Containers: only the name of the file: e.g. image.jpeg

Select with DoSQL• DoSQL can retrieve the data like ExecuteSQL

if you want

• FQL-engine does support native FileMaker types, so does myFMbutler DoSQL 2

• DoSQL supports container fields

• Compatible with FileMaker Pro 11 and above

Select with DoSQLmFMb_DoSQL_SetParameters ( myTable::Department)

mFMb_DoSQL ("SELECT sum(salary), Name, EmpID, Department FROM Employees WHERE Department = ?"; false)

Result

• Row Count

• Use mFMb_DoSQL_Result ( row ; column )

• Result in native FileMaker Datatypes, no need to convert.

ResultLet([p = mFMb_DoSQL_SetParameters ( myTable::Department);q = mFMb_DoSQL("SELECT sum(salary) FROM Employees WHERE Department = ?"; false) ;x = mFMb_DoSQL_Result ( 1 ; 1 )];x < 20 000) False

1 000 000< 20 000

INSERT, UPDATE & DELETE

• Supported through JDBC, ODBC and the plug-in API

• NOT supported through ExecuteSQL()

• So plug-ins are the only ones capable of supporting FQL fully from the inside

Let’s start with INSERT

• syntax: INSERT INTO table_name [(column_name, ...)] VALUES (expr, ...)

• can be a prepared statement ( it better be )

• VALUES can be a SELECT expression

• can be a lot faster than a script doing new record, set field, set field,… why?

Committing records

• for JDBC & ODBC this is a setting

• the plug-in API is always auto-committing and has no cursor support

INSERT

• No need to change the context

• Logging

• Audit trail

• Creating statistics, reports, ...

So, You Think You Can UPDATE

• UPDATE table_name SET column_name = expr, ... [ WHERE { conditions } ]

• A user can lock a record

• the error codes returned are the FileMaker error codes ( e.g. 301 )!

• compare with SELECT, it will never return error 401

Select for update

• SELECT for UPDATE only locks records on JDBC and ODBC

• plug-in cannot lock a record, but SELECT for UPDATE returns error when records are locked

• user can lock a record

UPDATE

• No need to change the context

• Changing data (in bulk) of related records

• Triggering auto-enter calculations of related records

Delete

• DELETE FROM table_name [ WHERE { conditions } ]

• check for record locking!

• check for privileges!

DELETE

• Conditional deletes (of related records)

Modifying Structure using SQL

• this is dangerous stuff, keep backups

• a calculation field cannot return a result when the schema is being changed, this results in a deadlock

• modifying schema on idle can be done using DoSQL 2.

Other features of DoSQL 2

SQL for dummies

• Generates the SQL for you

• mFMb_DoSQL_Select

• mFMb_DoSQL_Insert

• mFMb_DoSQL_Delete

mFMb_DoSQL_SelectmFMb_DoSQL ("SELECT citizens, categoryFROM citiesWHERE city = ‘Gent’")

mFMb_DoSQL_SelectLet([t able= GetValue(Substitute(GetFieldName(cities::citizens); “::”; “¶”); 1 );field1= GetValue(Substitute(GetFieldName(cities::citizens); “::”; “¶”); 2 );field2= GetValue(Substitute(GetFieldName(cities::category); “::”; “¶”); 2 );field3= GetValue(Substitute(GetFieldName(cities::city); “::”; “¶”); 2 );q = mFMb_DoSQL ("SELECT " & field1 & ", " & field1 &" FROM " & table " WHERE " & field2 & " = ‘Gent’")];q)

mFMb_DoSQL_SelectmFMb_DoSQL _Select(GetFieldName(cities::citizens); GetFieldName(cities::category); “WHERE”; GetFieldName(cities::city); “Gent”)

Debug tools

• Errors

• Log

• Alert dialog

Errors

• mFMb_DoSQL_LastErrNum( )

• returns the last error

• mFMb_DoSQL_LastSQL( )

• returns the last query

Logs

• Logging can be enabled by the funtion:mFMb_DoSQL_Debug( level { ; once }

• Level 1: Only errors

• Level 2: All queries

Logs2012-01-19 10:34:53.674 Select Count ( MAILBOXID_DNR ) from mailboxes where parentmailboxid_dnr = 7009

2012-01-19 10:34:53.674 ERROR: 8310ERROR: FQL0001/(1:18): There is an error in the syntax of the query.

Logs2012-01-19 10:34:54.043 Running Script: "Read Messages"2012-01-19 10:34:54.043 SELECT Count ( "messageid" ) FROM "mailboxes_messagereceivers" WHERE "mbdef_id" = 6 AND "contactid" = 1000843 AND "is_unread" = 12012-01-19 10:34:54.045 rows in result: 12012-01-19 10:34:54.045 columns in result: 12012-01-19 10:34:54.046 resultsize: 22012-01-19 10:34:54.046 result has been retrieved

• mFMb_DoSQL_SupressAlerts()

Alert dialog

Common mistakes

Use hard coded !eld names

• Do not use GetFieldName ( field ) instead

• Do not push FileMaker to solve GetFieldName() validation bugs with unrelated fields

Linda DuBose - http://www.sxc.hu

Use SQL in Stored Calculations

• And see the continents move while your schema recalculates

Never check for errors

• Just assume you SQL queries are perfect

• ExecuteSQL(): never check for Get ( LastError )

• DoSQL: set DoSQL_SupressAlerts( True ) and never use DoSQL_LastErrNum

Michael & Christa Richert - http://www.sxc.hu

Leave your queries in the data viewer

• when you are finished with debuggingand use your computer to grill your meat

Chris Chidsey - http://www.sxc.hu

Do more with SQL

• Even when it’s faster to do it using old school methods

• Know that because SQL calculation are harder to write, they must be the better way do to things

Everythin

g

Do more with SQL in FileMaker

• uses SQL statements to select, update, create or delete FileMaker records.

• doesn't require any drivers

• Returns native FileMaker data types like dates, images, formatted text,

• Debug tools

DoSQL 2License Price FM Server1 user

5 users10 users25 users50 users

Developer (25)Site license

29,- EUR (± 38,- USD)

99,- EUR (± 132,- USD)

169,- EUR (± 226,- USD)

259,- EUR (± 346,- USD)

469,- EUR (± 627,- USD)

339,- EUR (± 453,- USD) YES

559,- EUR (± 747,- USD) YES

Thank you!

www.myfmbutler.comor visit our booth

Recommended