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
Tables1
Relationships0
Layouts1
Scripts4
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
Query
6 fields defined, 11 records
Query

Fields

Table Name: 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
                      PathToSQLLibraryNormal, TextAuto-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 PropertiesCoordinatesField FormatField BehaviorQuick 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 PropertiesCoordinatesField FormatField BehaviorQuick 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 PropertiesCoordinatesField FormatField BehaviorQuick 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 PropertiesCoordinatesField FormatField BehaviorQuick 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 PropertiesCoordinatesField FormatField BehaviorQuick 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 PropertiesCoordinatesField FormatField BehaviorQuick 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 PropertiesCoordinatesScript/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 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 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
                            • #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
                            • 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 [ 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 NameClear
                                    Run script with full access privilegesOff
                                    Include In MenuYes
                                    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 NameInsert with Transaction
                                                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 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 NameInsert with Transaction and Errors
                                                            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 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: