Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

MBS FileMaker Plugin Example Databases

ODBC Query

All examples are included with download of MBS FileMaker Plugin.

ODBC Query.fmp12

Overview
Tables1
Relationships0
Layouts1
Scripts5
Value Lists0
Custom Functions0
Custom Menus33
File Options
Default custom menu set[Standard FileMaker Menus]
When opening file
Minimum allowed version12.0
Login usingAccount Name; Account= Admin
Allow user to save passwordOff
Require iOS passcodeOff
Switch to layoutOff
Hide all toolbarsOff
Script triggers
OnFirstWindowOpenOff
OnLastWindowCloseOff
OnWindowOpenOff
OnWindowCloseOff
OnFileAVPlayerChangeOff
Thumbnail Settings
Generate ThumbnailsOn; Temporary

 

Tables

Table Name
Statistics
Occurrences in Relationship Graph
ODBC Query
6 fields defined, 11 records
ODBC Query

Fields

Table Name: ODBC Query - 6 Fields
Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
SQLNormal, TextAuto-Enter:
  • Allow editing
Validation:
  • Only during data entry
Storage:
  • Repetitions: 1
  • Indexing: None
  • Automatically create indexes as needed
  • Index Language: German
      ResultNormal, TextAuto-Enter:
      • Allow editing
      Validation:
      • Only during data entry
      Storage:
      • Repetitions: 1
      • Indexing: None
      • Automatically create indexes as needed
      • Index Language: German
          UsernameNormal, TextAuto-Enter:
          • Allow editing
          Validation:
          • Only during data entry
          Storage:
          • Global
          • Repetitions: 1
          • Index Language: German
              PasswordNormal, TextAuto-Enter:
              • Allow editing
              Validation:
              • Only during data entry
              Storage:
              • Global
              • Repetitions: 1
              • Index Language: German
                  SQLConnectionStringNormal, TextAuto-Enter:
                  • Allow editing
                  Validation:
                  • Only during data entry
                  Storage:
                  • Global
                  • Repetitions: 1
                  • Index Language: German
                      PathToLibraryNormal, TextAuto-Enter:
                      • Allow editing
                      Validation:
                      • Only during data entry
                      Storage:
                      • Global
                      • Repetitions: 1
                      • Index Language: German

                          Layout Objects: ODBC Query

                          Regular Fields

                          Field Name: ODBC Query::SQL
                          Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                          • Top: 96 pt
                          • Left: 138 pt
                          • Bottom: 110 pt
                          • Right: 553 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: System Default
                          • Go to next field using: Tab key
                          Yes

                          Field Name: ODBC Query::Result
                          Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                          • Top: 114 pt
                          • Left: 138 pt
                          • Bottom: 320 pt
                          • Right: 553 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: System Default
                          • Go to next field using: Tab key
                          Yes

                          Field Name: ODBC Query::Username
                          Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                          • Top: 18 pt
                          • Left: 138 pt
                          • Bottom: 32 pt
                          • Right: 391 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: System Default
                          • Go to next field using: Tab key
                          No

                          Field Name: ODBC Query::Password
                          Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                          • Top: 36 pt
                          • Left: 138 pt
                          • Bottom: 50 pt
                          • Right: 391 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: System Default
                          • Go to next field using: Tab key
                          No

                          Field Name: ODBC Query::SQLConnectionString
                          Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                          • Top: 54 pt
                          • Left: 138 pt
                          • Bottom: 68 pt
                          • Right: 391 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: System Default
                          • Go to next field using: Tab key
                          No

                          Field Name: ODBC Query::PathToLibrary
                          Field PropertiesCoordinatesField FormatField BehaviorQuick Find
                          • Top: 72 pt
                          • Left: 138 pt
                          • Bottom: 86 pt
                          • Right: 391 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: System Default
                          • Go to next field using: Tab key
                          No

                          Group Buttons

                          Button PropertiesCoordinatesScript/Script Step
                            Type:
                          • Text: Run Query
                            Additional Properties:
                          • Change to hand cursor over button
                          • Rectangular
                          • Top: 24 pt
                          • Left: 414 pt
                          • Bottom: 49 pt
                          • Right: 493 pt
                          • Anchoring: Left, Top
                          Perform Script [ “RunQuery” ]

                          Scripts:


                          Script Hierarchy

                          RunQuery
                          get json
                          get json with error handling
                          copy records from SQL Server to FileMaker
                          copy records from FileMaker to SQL Server

                          Next Script: [get json]
                          Script NameRunQuery
                          Run script with full access privilegesOff
                          Include In MenuYes
                          Layouts that use this script
                          Scripts that use this script
                            Script Definition
                            Script Steps
                            • Set Variable [ $r; Value:MBS("Trace") ]
                            • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                            • #Tell plugin where MySQL library is
                            • If [ Length(ODBC Query::PathToLibrary) > 0 ]
                            • Set Variable [ $result; Value:MBS("SQL.SetConnectionOption"; $Connection; "ODBC.LIBS"; ODBC Query::PathToLibrary) ]
                            • End If
                            • #Tell plugin we want to use ODBC
                            • Set Variable [ $result; Value:MBS("SQL.SetClient"; $Connection; "ODBC") ]
                            • #Connect to database in read/write/create mode. Creates new file if none exists.
                            • Set Variable [ $result; Value:MBS("SQL.Connect"; $Connection; ODBC Query::SQLConnectionString; ODBC Query::Username; ODBC Query::Password; "ODBC") ]
                            • If [ $result ≠ "OK" ]
                            • Show Custom Dialog [ Message: "Error: " & $result; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                            • Set Variable [ $result; Value:MBS("SQL.FreeConnection"; $Connection) ]
                            • Halt Script
                            • End If
                            • #Create select and run it
                            • Set Variable [ $Command; Value:MBS("SQL.NewCommand"; $Connection; ODBC Query::SQL) ]
                            • #Run it
                            • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                            • If [ $result ≠ "OK" ]
                            • Set Field [ ODBC Query::Result; $result ]
                            • Show Custom Dialog [ Message: "Error: " & $result; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                            • Else
                            • Set Variable [ $lines; Value:"" ]
                            • Set Variable [ $fieldcount; Value:MBS("SQL.FieldCount"; $command) ]
                            • Loop
                            • Set Variable [ $result; Value:MBS("SQL.FetchNext"; $Command) ]
                            • Exit Loop If [ $result ≠ 1 ]
                            • Set Variable [ $line; Value:"" ]
                            • Set Variable [ $i; Value:1 ]
                            • Loop
                            • Set Variable [ $v; Value:MBS("SQL.GetFieldAsText"; $command; $i) ]
                            • Set Variable [ $n; Value:MBS("SQL.GetFieldName"; $command; $i) ]
                            • Set Variable [ $line; Value:$line & $n & ": " & $v & ¶ ]
                            • Set Variable [ $i; Value:$i+1 ]
                            • Exit Loop If [ $i > $fieldCount ]
                            • End Loop
                            • Set Variable [ $lines; Value:$lines & ($line & ¶) ]
                            • End Loop
                            • Set Variable [ $lines; Value:$lines & ¶ ]
                            • Set Field [ ODBC Query::Result; $lines ]
                            • End If
                            • #Cleanup
                            • Set Variable [ $result2; Value:MBS("SQL.FreeCommand"; $Command) ]
                            • Set Variable [ $result2; Value:MBS("SQL.FreeConnection"; $Connection) ]
                            Fields used in this script
                            Scripts used in this script
                              Layouts used in this script
                                Tables used in this script
                                Table occurrences used by this script
                                Custom Functions used by this script
                                  Custom menu set used by this script

                                    Previous Script: [RunQuery]Next Script: [get json with error handling]
                                    Script Nameget json
                                    Run script with full access privilegesOff
                                    Include In MenuYes
                                    Layouts that use this script
                                      Scripts that use this script
                                        Script Definition
                                        Script Steps
                                        • #connect to ODBC data source named "Test"
                                        • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                        • Set Variable [ $r; Value:MBS("SQL.Connect"; $Connection; "test"; ""; ""; "ODBC") ]
                                        • #run SQL query
                                        • Set Variable [ $Command; Value:MBS("SQL.NewCommand"; $Connection; "SELECT * FROM MyTable") ]
                                        • Set Variable [ $r; Value:MBS("SQL.Execute"; $Command) ]
                                        • #get JSON records
                                        • Set Variable [ $$json; Value:MBS( "SQL.GetRecordsAsJSON"; $Command ) ]
                                        • #cleanup
                                        • Set Variable [ $r; Value:MBS("SQL.FreeCommand"; $Command) ]
                                        • Set Variable [ $r; Value:MBS("SQL.FreeConnection"; $Connection) ]
                                        Fields used in this script
                                          Scripts used in this script
                                            Layouts used in this script
                                              Tables used in this script
                                                Table occurrences used by this script
                                                  Custom Functions used by this script
                                                    Custom menu set used by this script

                                                      Previous Script: [get json]Next Script: [copy records from SQL Server to FileMaker]
                                                      Script Nameget json with error handling
                                                      Run script with full access privilegesOff
                                                      Include In MenuYes
                                                      Layouts that use this script
                                                        Scripts that use this script
                                                          Script Definition
                                                          Script Steps
                                                          • #connect to ODBC data source named "Test"
                                                          • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                                          • Set Variable [ $r; Value:MBS("SQL.Connect"; $Connection; "test"; ""; ""; "ODBC") ]
                                                          • If [ MBS("IsError") ≠ 0 ]
                                                          • Show Custom Dialog [ Title: "Failed to connect"; Message: $r; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                                                          • Else
                                                          • #run SQL query
                                                          • Set Variable [ $Command; Value:MBS("SQL.NewCommand"; $Connection; "SELECT * FROM MyTable") ]
                                                          • If [ MBS("IsError") ≠ 0 ]
                                                          • Show Custom Dialog [ Title: "Failed to parse SQL"; Message: $command; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                                                          • Else
                                                          • Set Variable [ $r; Value:MBS("SQL.Execute"; $Command) ]
                                                          • If [ MBS("IsError") ≠ 0 ]
                                                          • Show Custom Dialog [ Title: "Failed to execute SQL"; Message: $r; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                                                          • Else
                                                          • #get JSON records
                                                          • Set Variable [ $$json; Value:MBS( "SQL.GetRecordsAsJSON"; $Command ) ]
                                                          • End If
                                                          • #cleanup
                                                          • Set Variable [ $r; Value:MBS("SQL.FreeCommand"; $Command) ]
                                                          • End If
                                                          • End If
                                                          • Set Variable [ $r; Value:MBS("SQL.FreeConnection"; $Connection) ]
                                                          Fields used in this script
                                                            Scripts used in this script
                                                              Layouts used in this script
                                                                Tables used in this script
                                                                  Table occurrences used by this script
                                                                    Custom Functions used by this script
                                                                      Custom menu set used by this script

                                                                        Previous Script: [get json with error handling]Next Script: [copy records from FileMaker to SQL Server]
                                                                        Script Namecopy records from SQL Server to FileMaker
                                                                        Run script with full access privilegesOff
                                                                        Include In MenuYes
                                                                        Layouts that use this script
                                                                          Scripts that use this script
                                                                            Script Definition
                                                                            Script Steps
                                                                            • #connect to ODBC data source named "Test"
                                                                            • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                                                            • Set Variable [ $r; Value:MBS("SQL.Connect"; $Connection; "test"; ""; ""; "ODBC") ]
                                                                            • #run SQL query
                                                                            • Set Variable [ $Command; Value:MBS("SQL.NewCommand"; $Connection; "SELECT FirstName, LastName, CityName, 123 FROM MyTable") ]
                                                                            • Set Variable [ $r; Value:MBS("SQL.Execute"; $Command) ]
                                                                            • #insert records to FileMaker
                                                                            • Set Variable [ $FieldNames; Value:"FirstName¶LastName¶City¶ImportID" ]
                                                                            • Set Variable [ $r; Value:MBS( "SQL.InsertRecords"; $Command; Get(FileName ); "Import" /* target table in FileMaker */; $FieldNames) ]
                                                                            • #cleanup
                                                                            • Set Variable [ $r; Value:MBS("SQL.FreeCommand"; $Command) ]
                                                                            • Set Variable [ $r; Value:MBS("SQL.FreeConnection"; $Connection) ]
                                                                            Fields used in this script
                                                                              Scripts used in this script
                                                                                Layouts used in this script
                                                                                  Tables used in this script
                                                                                    Table occurrences used by this script
                                                                                      Custom Functions used by this script
                                                                                        Custom menu set used by this script

                                                                                          Previous Script: [copy records from SQL Server to FileMaker]
                                                                                          Script Namecopy records from FileMaker to SQL Server
                                                                                          Run script with full access privilegesOff
                                                                                          Include In MenuYes
                                                                                          Layouts that use this script
                                                                                            Scripts that use this script
                                                                                              Script Definition
                                                                                              Script Steps
                                                                                              • #connect to ODBC data source named "Test"
                                                                                              • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                                                                              • Set Variable [ $r; Value:MBS("SQL.Connect"; $Connection; "test"; ""; ""; "ODBC") ]
                                                                                              • #run SQL query in FileMaker
                                                                                              • Set Variable [ $Records; Value:MBS( "FM.SQL.Execute"; Get(FileName); "SELECT FirstName, LastName, \"City Name\" FROM Import") ]
                                                                                              • #insert records to SQL database
                                                                                              • Set Variable [ $FieldNames; Value:"FirstName¶LastName¶City" ]
                                                                                              • Set Variable [ $r; Value:MBS( "FM.SQL.InsertRecordsToSQL"; $Records; $Connection; "Export" /* target table in SQL */; $FieldNames) ]
                                                                                              • #cleanup
                                                                                              • Set Variable [ $r; Value:MBS("FM.SQL.Release"; $Records) ]
                                                                                              • Set Variable [ $r; Value:MBS("SQL.FreeConnection"; $Connection) ]
                                                                                              Fields used in this script
                                                                                                Scripts used in this script
                                                                                                  Layouts used in this script
                                                                                                    Tables used in this script
                                                                                                      Table occurrences used by this script
                                                                                                        Custom Functions used by this script
                                                                                                          Custom menu set used by this script

                                                                                                            Download example: ODBC Query

                                                                                                            Used functions: