Vendor session myFMbutler DoSQL 2

11,059 views

Published on

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

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
11,059
On SlideShare
0
From Embeds
0
Number of Embeds
9,234
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Vendor session myFMbutler DoSQL 2

  1. 1. Do more with SQL in FileMaker Koen Van Hulle
  2. 2. Koen Van Hulle
  3. 3. Gent Niels Heyvaert - http://www.sxc.hu
  4. 4. Belgium Linda DuBose Vince Varga - http://www.sxc.hu
  5. 5. I work at • FileMaker“7...12”Certified developer • 2012 FileMaker Mad Dog PR Award
  6. 6. better known as • FileMaker Hosting • Tools and add-ons for FileMaker FMbutlermy
  7. 7. our product range
  8. 8. 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
  9. 9. 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.
  10. 10. 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
  11. 11. 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
  12. 12. Menu • FQL Engine demystified • Overview of most common SQL commands • Other DoSQL Commands • Common mistakes
  13. 13. 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)
  14. 14. One FQL engine, four interfaces ODBC driver JDBC driver plug-in API executeSQL
  15. 15. Outside ODBC driver JDBC driver plug-in API executeSQL Inside Credentials at login Credentials of the current user
  16. 16. plug-in API executeSQL Inside Credentials of the current user
  17. 17. Selecting a database
  18. 18. ExecuteSQL() • only the file of the calculation context
  19. 19. Plug-in API • any existing open file with second generation plug-ins
  20. 20. What does the FQL engine support? • SQL-92 • SELECT • DELETE • INSERT • UPDATE • CREATE TABLE • ALTER TABLE • CREATE INDEX • DROP INDEX
  21. 21. What does executeSQL support? • SQL-92 • SELECT • DELETE • INSERT • UPDATE • CREATE TABLE • ALTER TABLE • CREATE INDEX • DROP INDEX
  22. 22. SELECT SELECT[DISTINCT]{*|column_expression[[AS]column_alias],...} FROMtable_name[table_alias],... [WHEREexpr1rel_operatorexpr2] [GROUPBY{column_expression,...}] [HAVINGexpr1rel_operatorexpr2] [UNION[ALL](SELECT...)] [ORDERBY{sort_expression[DESC|ASC]},...] [OFFSETn{ROWS|ROW}] [FETCHFIRST[n[PERCENT]]{ROWS|ROW}{ONLY|WITHTIES}] [FORUPDATE[OF{column_expression,...}]]
  23. 23. SELECT SELECTsum(salary),Name,EmpID,Department FROMEmployees WHEREDepartment=‘marketing’
  24. 24. SELECT ExecuteSQL( “SELECTsum(salary),Name,EmpID,Department FROMEmployees WHEREDepartment=‘marketing’” ;”;”;“¶”) 1000000;WillySommers;203;marketing 1000000;DanaWinner;204;marketing 1000000;EvaDeWaelle;205;marketing 1000000;MaartenCox;206;marketing 1000000;DannyFabry;207;marketing
  25. 25. SELECT ExecuteSQL( “SELECTsum(salary),Name,EmpID,Department FROMEmployees WHEREDepartment=?” ;”;”;“¶”; globals::department) 1000000;WillySommers;203;marketing 1000000;DanaWinner;204;marketing 1000000;EvaDeWaelle;205;marketing 1000000;MaartenCox;206;marketing 1000000;DannyFabry;207;marketing
  26. 26. RESULT • Always TEXT • Always one TEXT string per query
  27. 27. Result = Text Let( x=ExecuteSQL("SELECTsum(salary) FROMEmployees WHEREDepartment=?"; "";"";globals::department); x<20000) *sum(salary)=1000000 TRUE“1000000”<20000
  28. 28. Result = Text Let( x=ExecuteSQL("SELECTsum(salary) FROMEmployees WHEREDepartment=?"; "";"";globals::department); GetAsNumber(x)<20000) *sum(salary)=1000000 False1000000<20000
  29. 29. 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
  30. 30. 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
  31. 31. Select with DoSQL mFMb_DoSQL_SetParameters (myTable::Department) mFMb_DoSQL("SELECTsum(salary),Name,EmpID, Department FROMEmployees WHEREDepartment=?"; false)
  32. 32. Result • Row Count • Use mFMb_DoSQL_Result ( row ; column ) • Result in native FileMaker Datatypes, no need to convert.
  33. 33. Result Let([ p=mFMb_DoSQL_SetParameters(myTable::Department); q=mFMb_DoSQL("SELECTsum(salary) FROMEmployees WHEREDepartment=?"; false); x=mFMb_DoSQL_Result(1;1)]; x<20000) False1000000<20000
  34. 34. 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
  35. 35. 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?
  36. 36. Committing records • for JDBC & ODBC this is a setting • the plug-in API is always auto-committing and has no cursor support
  37. 37. INSERT • No need to change the context • Logging • Audit trail • Creating statistics, reports, ...
  38. 38. 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
  39. 39. 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
  40. 40. UPDATE • No need to change the context • Changing data (in bulk) of related records • Triggering auto-enter calculations of related records
  41. 41. Delete • DELETE FROM table_name [ WHERE { conditions } ] • check for record locking! • check for privileges!
  42. 42. DELETE • Conditional deletes (of related records)
  43. 43. 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.
  44. 44. Other features of DoSQL 2
  45. 45. SQL for dummies • Generates the SQL for you • mFMb_DoSQL_Select • mFMb_DoSQL_Insert • mFMb_DoSQL_Delete
  46. 46. mFMb_DoSQL_Select mFMb_DoSQL("SELECTcitizens,category FROMcities WHEREcity=‘Gent’")
  47. 47. mFMb_DoSQL_Select Let([ table=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)
  48. 48. mFMb_DoSQL_Select mFMb_DoSQL_Select( GetFieldName(cities::citizens); GetFieldName(cities::category); “WHERE”; GetFieldName(cities::city); “Gent” )
  49. 49. Debug tools • Errors • Log • Alert dialog
  50. 50. Errors • mFMb_DoSQL_LastErrNum( ) • returns the last error • mFMb_DoSQL_LastSQL( ) • returns the last query
  51. 51. Errors • http://wiki.myfmbutler.com/index.php/ DoSQL_2#Errors_returned_by_DoSQL • Plug-in Errors • FQL Errors
  52. 52. Logs • Logging can be enabled by the funtion: mFMb_DoSQL_Debug( level { ; once } • Level 1: Only errors • Level 2: All queries
  53. 53. Logs 2012-01-1910:34:53.674SelectCount(MAILBOXID_DNR)from mailboxeswhereparentmailboxid_dnr=7009 2012-01-1910:34:53.674ERROR:8310 ERROR:FQL0001/(1:18):Thereisanerrorinthesyntaxofthequery.
  54. 54. Logs 2012-01-1910:34:54.043RunningScript:"ReadMessages" 2012-01-1910:34:54.043SELECTCount("messageid")FROM "mailboxes_messagereceivers"WHERE"mbdef_id"=6AND"contactid" =1000843AND"is_unread"=1 2012-01-1910:34:54.045rowsinresult:1 2012-01-1910:34:54.045columnsinresult:1 2012-01-1910:34:54.046resultsize:2 2012-01-1910:34:54.046resulthasbeenretrieved
  55. 55. • mFMb_DoSQL_SupressAlerts() Alert dialog
  56. 56. Common mistakes
  57. 57. Use hard coded field 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
  58. 58. Use SQL in Stored Calculations • And see the continents move while your schema recalculates
  59. 59. 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
  60. 60. Leave your queries in the data viewer • when you are finished with debugging and use your computer to grill your meat Chris Chidsey - http://www.sxc.hu
  61. 61. 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 Everything
  62. 62. 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
  63. 63. DoSQL 2 License Price FM Server 1 user 5 users 10 users 25 users 50 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
  64. 64. Thank you! www.myfmbutler.com or visit our booth

×