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

MBS FileMaker Plugin Example Databases

PostgreSQL Query

All examples are included with download of MBS FileMaker Plugin.

PostgreSQL Query.fmp12

Overview
Tables 1
Relationships 0
Layouts 1
Scripts 4
Value Lists 0
Custom Functions 0
Custom Menus 33
File Options
Default custom menu set [Standard FileMaker Menus]
Default theme Minimalistisch
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, 11 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: 149 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: 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: 153 pt
                          • Left: 138 pt
                          • Bottom: 415 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: 72 pt
                          • Left: 473 pt
                          • Bottom: 103 pt
                          • Right: 611 pt
                          • Anchoring: Left, Top
                          Perform Script [ “RunQuery” ]

                          Scripts:


                          Script Hierarchy

                          RunQuery
                          Clear
                          Insert with Transaction
                          Insert with Transaction and Errors

                          Next Script: [Clear]
                          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 [ $r; Value:MBS("Trace") ]
                            • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                            • #Tell plugin where PostgreSQL library is
                            • Set Variable [ $result; Value:MBS("SQL.SetConnectionOption"; $Connection; "LIBPQ.LIBS"; Query::PathToSQLLibrary) ]
                            • #Connect to database
                            • Set Variable [ $result; Value:MBS("SQL.Connect"; $Connection; Query::SQLConnectionString; Query::Username; Query::Password; "PostgreSQL") ]
                            • 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: [Insert with Transaction]
                                    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
                                        • Set Field [ Query::Result; "" ]
                                        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: [Clear] Next Script: [Insert with Transaction and Errors]
                                                Script Name Insert with Transaction
                                                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 [ $r; Value:MBS("Trace") ]
                                                    • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                                    • #Tell plugin where PostgreSQL library is
                                                    • Set Variable [ $result; Value:MBS("SQL.SetConnectionOption"; $Connection; "LIBPQ.LIBS"; Query::PathToSQLLibrary) ]
                                                    • #Connect to database in read/write/create mode. Creates new file if none exists.
                                                    • Set Variable [ $result; Value:MBS("SQL.Connect"; $Connection; Query::SQLConnectionString; Query::Username; Query::Password; "PostgreSQL") ]
                                                    • 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
                                                    • #auto commit off
                                                    • Set Variable [ $r; Value:MBS( "SQL.SetAutoCommit"; $Connection; "off" ) ]
                                                    • #Create insert command with setting values
                                                    • Set Variable [ $Command; Value:MBS("SQL.NewCommand"; $Connection; "INSERT INTO Persons (FirstName, LastName, City) VALUES (:FirstName, :LastName, :City)") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "FirstName"; "John") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "LastName"; "Meyer") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "City"; "Boston") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "FirstName"; "Monica") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "LastName"; "Jones") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "City"; "San Francisco") ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                                                    • If [ MBS("IsError") = 0 ]
                                                    • #all okay, so let's commit
                                                    • Set Variable [ $result2; Value:MBS("SQL.Commit"; $Connection) ]
                                                    • End If
                                                    • End If
                                                    • End If
                                                    • End If
                                                    • End If
                                                    • End If
                                                    • End If
                                                    • End If
                                                    • Set Variable [ $result2; Value:MBS("SQL.FreeCommand"; $Command) ]
                                                    • #if anything got wrong, do a rollback
                                                    • Set Variable [ $result2; Value:MBS("SQL.Rollback"; $Connection) ]
                                                    • End If
                                                    • 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: [Insert with Transaction]
                                                            Script Name Insert with Transaction and Errors
                                                            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 [ $r; Value:MBS("Trace") ]
                                                                • Set Variable [ $Connection; Value:MBS("SQL.NewConnection") ]
                                                                • #Tell plugin where PostgreSQL library is
                                                                • Set Variable [ $result; Value:MBS("SQL.SetConnectionOption"; $Connection; "LIBPQ.LIBS"; Query::PathToSQLLibrary) ]
                                                                • #Connect to database in read/write/create mode. Creates new file if none exists.
                                                                • Set Variable [ $result; Value:MBS("SQL.Connect"; $Connection; Query::SQLConnectionString; Query::Username; Query::Password; "PostgreSQL") ]
                                                                • 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
                                                                • #let the plugin count errors
                                                                • Set Variable [ $r; Value:MBS( "ClearErrors" ) ]
                                                                • #auto commit off
                                                                • Set Variable [ $r; Value:MBS( "SQL.SetAutoCommit"; $Connection; "off" ) ]
                                                                • #Create insert command with setting values
                                                                • Set Variable [ $Command; Value:MBS("SQL.NewCommand"; $Connection; "INSERT INTO Persons (FirstName, LastName, City) VALUES (:FirstName, :LastName, :City)") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "FirstName"; "John") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "LastName"; "Meyer") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "City"; "Boston") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                                                                • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "FirstName"; "Monica") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "LastName"; "Jones") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.SetParamAsText"; $Command; "City"; "San Francisco") ]
                                                                • Set Variable [ $result; Value:MBS("SQL.Execute"; $Command) ]
                                                                • If [ MBS("HadErrors") = 0 ]
                                                                • #all okay, so let's commit
                                                                • Set Variable [ $result2; Value:MBS("SQL.Commit"; $Connection) ]
                                                                • Else [ ]
                                                                • #we had errors!
                                                                • Set Variable [ $result2; Value:MBS("SQL.Rollback"; $Connection) ]
                                                                • End If
                                                                • 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

                                                                        Download example: PostgreSQL Query

                                                                        Used functions: