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

MBS FileMaker Plugin Example Databases

DuckDB Query

All examples are included with download of MBS FileMaker Plugin.

DuckDB Query.fmp12

Overview
Tables 1
Relationships 0
Layouts 1
Scripts 3
Value Lists 0
Custom Functions 0
Custom Menus 33
File Options
Default custom menu set [Standard FileMaker Menus]
Default theme Apex Blue
When opening file
Minimum allowed version 12.0
Login using Account Name; Account= Admin
Allow user to save password On
Require iOS passcode Off
Show Sign-in fields Off
Switch to layout Off
Hide all toolbars Off
Script triggers
OnFirstWindowOpen Off
OnLastWindowClose Off
OnWindowOpen Off
OnWindowClose Off
OnFileAVPlayerChange Off
OnWindowTransaction Off
Thumbnail Settings
Generate Thumbnails On; Temporary

 

Tables

Table Name
Statistics
Comments
Occurrences in Relationship Graph
Query
6 fields defined, 3 records
Query

Fields

Table Name: Query - 6 Fields
Field Name Type Options Comments On Layouts In Relationships In Scripts In Value Lists
SQL Normal, Text Auto-Enter:
  • Allow editing
Validation:
  • Only during data entry
Storage:
  • Repetitions: 1
  • Indexing: None
  • Automatically create indexes as needed
  • Index Language: German
      Result Normal, Text Auto-Enter:
      • Allow editing
      Validation:
      • Only during data entry
      Storage:
      • Repetitions: 1
      • Indexing: None
      • Automatically create indexes as needed
      • Index Language: German
          Username Normal, Text Auto-Enter:
          • Allow editing
          Validation:
          • Only during data entry
          Storage:
          • Global
          • Repetitions: 1
          • Index Language: German
              Password Normal, Text Auto-Enter:
              • Allow editing
              Validation:
              • Only during data entry
              Storage:
              • Global
              • Repetitions: 1
              • Index Language: German
                  SQLConnectionString Normal, Text Auto-Enter:
                  • Allow editing
                  Validation:
                  • Only during data entry
                  Storage:
                  • Global
                  • Repetitions: 1
                  • Index Language: German
                      PathToSQLLibrary Normal, Text Auto-Enter:
                      • Allow editing
                      Validation:
                      • Only during data entry
                      Storage:
                      • Global
                      • Repetitions: 1
                      • Index Language: German

                          Layout Objects: Query

                          Regular Fields

                          Field Name: Query::Username
                          Field Properties Coordinates Field Format Field Behavior Quick Find
                          • Top: 15 pt
                          • Left: 138 pt
                          • Bottom: 34 pt
                          • Right: 462 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: Default for Data Type
                          • Go to next field using: Tab key
                          No

                          Field Name: Query::Password
                          Field Properties Coordinates Field Format Field Behavior Quick Find
                          • Top: 38 pt
                          • Left: 138 pt
                          • Bottom: 57 pt
                          • Right: 462 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: Default for Data Type
                          • Go to next field using: Tab key
                          No

                          Field Name: Query::SQLConnectionString
                          Field Properties Coordinates Field Format Field Behavior Quick Find
                          • Top: 61 pt
                          • Left: 138 pt
                          • Bottom: 80 pt
                          • Right: 462 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: Default for Data Type
                          • Go to next field using: Tab key
                          No

                          Field Name: Query::PathToSQLLibrary
                          Field Properties Coordinates Field Format Field Behavior Quick Find
                          • Top: 84 pt
                          • Left: 138 pt
                          • Bottom: 103 pt
                          • Right: 462 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: Default for Data Type
                          • Go to next field using: Tab key
                          No

                          Field Name: Query::SQL
                          Field Properties Coordinates Field Format Field Behavior Quick Find
                          • Top: 130 pt
                          • Left: 138 pt
                          • Bottom: 173 pt
                          • Right: 762 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: Default for Data Type
                          • Go to next field using: Tab key
                          Yes

                          Field Name: Query::Result
                          Field Properties Coordinates Field Format Field Behavior Quick Find
                          • Top: 180 pt
                          • Left: 138 pt
                          • Bottom: 442 pt
                          • Right: 762 pt
                          • Anchoring: Left, Top
                          Field Format:
                          • Edit Box
                          Field Behavior:
                          • Allow field to be entered: In Find mode, In Browse mode
                          • Touch keyboard type: Default for Data Type
                          • Go to next field using: Tab key
                          Yes

                          Buttons

                          Button Properties Coordinates Script/Script Step
                            Type:
                          • Text: Run Query
                          • Top: 129 pt
                          • Left: 780 pt
                          • Bottom: 160 pt
                          • Right: 918 pt
                          • Anchoring: Left, Top
                          Perform Script [ “RunQuery” ]

                          Scripts:


                          Script Hierarchy

                          RunQuery
                          Query Version
                          Clear

                          Next Script: [Query Version]
                          Script Name RunQuery
                          Run script with full access privileges Off
                          Siri Shortcut Visible Off
                          Include In Menu Yes
                          Layouts that use this script
                          Scripts that use this script
                            Script Definition
                            Script Steps
                            • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                            • #Tell plugin where DuckDB library is
                            • Set Variable [ $result; Value:MBS("SQL.SetConnectionOption"; $Connection; "DUCKDB.LIBS"; Query::PathToSQLLibrary) ]
                            • #Connect to database
                            • Set Variable [ $result; Value:MBS("SQL.Connect"; $Connection; Query::SQLConnectionString; Query::Username; Query::Password; "DuckDB") ]
                            • 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; Query::SQL) ]
                            • #Run it
                            • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                            • If [ $result ≠ "OK" ]
                            • Set Field [ 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 [ Flush: Always ]
                            • Set Variable [ $result; Value:MBS("SQL.FetchNext"; $Command) ]
                            • Exit Loop If [ $result ≠ 1 ]
                            • Set Variable [ $line; Value:"" ]
                            • Set Variable [ $i; Value:1 ]
                            • Loop [ Flush: Always ]
                            • 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 [ 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: [Clear]
                                    Script Name Query Version
                                    Run script with full access privileges Off
                                    Siri Shortcut Visible Off
                                    Include In Menu Yes
                                    Layouts that use this script
                                      Scripts that use this script
                                        Script Definition
                                        Script Steps
                                        • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                        • #Tell plugin where DuckDB library is
                                        • Set Variable [ $result; Value:MBS("SQL.SetConnectionOption"; $Connection; "DUCKDB.LIBS"; Query::PathToSQLLibrary) ]
                                        • #Connect to database
                                        • Set Variable [ $result; Value:MBS("SQL.Connect"; $Connection; Query::SQLConnectionString; Query::Username; Query::Password; "DuckDB") ]
                                        • 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; "SELECT version() AS version;") ]
                                        • #Run it
                                        • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                                        • If [ $result ≠ "OK" ]
                                        • Set Field [ Query::Result; $result ]
                                        • Show Custom Dialog [ Message: "Error: " & $result; Default Button: “OK”, Commit: “No”; Button 2: “Abbrechen”, Commit: “No” ]
                                        • Else [ ]
                                        • #get first record
                                        • Set Variable [ $result; Value:MBS("SQL.FetchNext"; $Command) ]
                                        • #get version value
                                        • Set Variable [ $v; Value:MBS("SQL.GetFieldAsText"; $command; 1) ]
                                        • Show Custom Dialog [ Title: "Version"; Message: $v; Default Button: “OK”, Commit: “Yes” ]
                                        • Set Field [ Query::Result; $v ]
                                        • 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: [Query Version]
                                                Script Name Clear
                                                Run script with full access privileges Off
                                                Siri Shortcut Visible Off
                                                Include In Menu Yes
                                                Layouts that use this script
                                                  Scripts that use this script
                                                    Script Definition
                                                    Script Steps
                                                    • Replace Field Contents [ Query::Result; Replace with calculation: "" ] [ No dialog ]
                                                    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: DuckDB Query

                                                            Used functions: