create a delphi pascal programm with a postgres customer example database qwen3 entschied sich für eine Konsolenlösung, alles in einem "BEGIN - END". Press enter to Exit halt dann. ;-) Hardware: Ryzen 3950 RAM : 64 GB GPU : RX 5700 XT Here's a complete Delphi Pascal console application that demonstrates working with a PostgreSQL customer database: ```pascal program CustomerDatabaseExample; {$APPTYPE CONSOLE} uses System.SysUtils, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Stan.Connection, FireDAC.Stan.Error, FireDAC.Phys.Intf, FireDAC.Phys.PGSQLDef, FireDAC.Phys.PGSQL, FireDAC.VCLUI.Wait, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Stan.Connection, FireDAC.Stan.Error, FireDAC.Phys.Intf, FireDAC.Phys.PGSQLDef, FireDAC.Phys.PGSQL, FireDAC.VCLUI.Wait, Data.DB, FireDAC.DApt, FireDAC.DApt.Intf, FireDAC.DatS; var FDConnection: TFDConnection; FDQuery: TFDQuery; i: Integer; begin try // Create connection and query objects FDConnection := TFDConnection.Create(nil); FDQuery := TFDQuery.Create(nil); try // Configure PostgreSQL connection FDConnection.DriverID := 'PGSQL'; FDConnection.Params.Clear; FDConnection.Params.Add('Database=customerdb'); FDConnection.Params.Add('User_Name=postgres'); FDConnection.Params.Add('Password=mypassword'); FDConnection.Params.Add('Server=localhost'); FDConnection.Params.Add('Port=5432'); // Connect to database FDConnection.Connected := True; Writeln('Connected to PostgreSQL database successfully!'); Writeln(''); // Create sample customer table if it doesn't exist FDQuery.Connection := FDConnection; FDQuery.SQL.Text := 'CREATE TABLE IF NOT EXISTS customers (' + 'id SERIAL PRIMARY KEY, ' + 'first_name VARCHAR(50) NOT NULL, ' + 'last_name VARCHAR(50) NOT NULL, ' + 'email VARCHAR(100) UNIQUE NOT NULL, ' + 'phone VARCHAR(20), ' + 'address TEXT, ' + 'created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)'; FDQuery.ExecSQL; Writeln('Customer table created/verified successfully!'); // Insert sample data FDQuery.SQL.Text := 'INSERT INTO customers (first_name, last_name, email, phone, address) ' + 'VALUES ' + '(:fname1, :lname1, :email1, :phone1, :address1), ' + '(:fname2, :lname2, :email2, :phone2, :address2), ' + '(:fname3, :lname3, :email3, :phone3, :address3)'; FDQuery.ParamByName('fname1').Value := 'John'; FDQuery.ParamByName('lname1').Value := 'Doe'; FDQuery.ParamByName('email1').Value := 'john.doe@example.com'; FDQuery.ParamByName('phone1').Value := '+1234567890'; FDQuery.ParamByName('address1').Value := '123 Main St, City, State'; FDQuery.ParamByName('fname2').Value := 'Jane'; FDQuery.ParamByName('lname2').Value := 'Smith'; FDQuery.ParamByName('email2').Value := 'jane.smith@example.com'; FDQuery.ParamByName('phone2').Value := '+1234567891'; FDQuery.ParamByName('address2').Value := '456 Oak Ave, City, State'; FDQuery.ParamByName('fname3').Value := 'Bob'; FDQuery.ParamByName('lname3').Value := 'Johnson'; FDQuery.ParamByName('email3').Value := 'bob.johnson@example.com'; FDQuery.ParamByName('phone3').Value := '+1234567892'; FDQuery.ParamByName('address3').Value := '789 Pine Rd, City, State'; FDQuery.ExecSQL; Writeln('Sample data inserted successfully!'); // Query all customers FDQuery.SQL.Text := 'SELECT * FROM customers ORDER BY id'; FDQuery.Open; Writeln('All Customers:'); Writeln('=============='); while not FDQuery.Eof do begin Writeln(Format('ID: %d, Name: %s %s, Email: %s, Phone: %s', [FDQuery.FieldByName('id').AsInteger, FDQuery.FieldByName('first_name').AsString, FDQuery.FieldByName('last_name').AsString, FDQuery.FieldByName('email').AsString, FDQuery.FieldByName('phone').AsString])); FDQuery.Next; end; Writeln(''); // Query specific customer FDQuery.Close; FDQuery.SQL.Text := 'SELECT * FROM customers WHERE email = :email'; FDQuery.ParamByName('email').Value := 'jane.smith@example.com'; FDQuery.Open; if not FDQuery.Eof then begin Writeln('Specific Customer:'); Writeln('=================='); Writeln(Format('ID: %d, Name: %s %s, Email: %s, Phone: %s, Address: %s', [FDQuery.FieldByName('id').AsInteger, FDQuery.FieldByName('first_name').AsString, FDQuery.FieldByName('last_name').AsString, FDQuery.FieldByName('email').AsString, FDQuery.FieldByName('phone').AsString, FDQuery.FieldByName('address').AsString])); end; // Update customer FDQuery.Close; FDQuery.SQL.Text := 'UPDATE customers SET phone = :phone WHERE email = :email'; FDQuery.ParamByName('phone').Value := '+9998887777'; FDQuery.ParamByName('email').Value := 'john.doe@example.com'; FDQuery.ExecSQL; Writeln('Customer updated successfully!'); // Delete customer FDQuery.SQL.Text := 'DELETE FROM customers WHERE email = :email'; FDQuery.ParamByName('email').Value := 'bob.johnson@example.com'; FDQuery.ExecSQL; Writeln('Customer deleted successfully!'); // Final query to show remaining customers FDQuery.Close; FDQuery.SQL.Text := 'SELECT * FROM customers ORDER BY id'; FDQuery.Open; Writeln('Remaining Customers:'); Writeln('===================='); while not FDQuery.Eof do begin Writeln(Format('ID: %d, Name: %s %s, Email: %s', [FDQuery.FieldByName('id').AsInteger, FDQuery.FieldByName('first_name').AsString, FDQuery.FieldByName('last_name').AsString, FDQuery.FieldByName('email').AsString])); FDQuery.Next; end; except on E: Exception do Writeln('Error: ', E.Message); end; // Cleanup FDQuery.Free; FDConnection.Free; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Writeln(''); Writeln('Press Enter to exit...'); Readln; end. ``` **Important Setup Instructions:** 1. **Install Required Components:** - Install FireDAC components in Delphi (usually included with recent versions) - Install PostgreSQL ODBC driver or use FireDAC's native PostgreSQL driver - Ensure PostgreSQL server is running 2. **Database Setup:** - Create a database named `customerdb` in PostgreSQL - Update connection parameters in the code: ```pascal FDConnection.Params.Add('Database=customerdb'); FDConnection.Params.Add('User_Name=postgres'); FDConnection.Params.Add('Password=mypassword'); ``` 3. **Connection Parameters:** - Change `Server=localhost` to your PostgreSQL server address - Change `Port=5432` to your PostgreSQL port if different **Features Demonstrated:** - Connection to PostgreSQL database - Table creation with proper schema - Inserting sample customer data - Querying all records - Querying specific record - Updating customer information - Deleting customers - Error handling - Proper resource cleanup **Expected Output:** ``` Connected to PostgreSQL database successfully! Customer table created/verified successfully! Sample data inserted successfully! All Customers: ============== ID: 1, Name: John Doe, Email: john.doe@example.com, Phone: +1234567890 ID: 2, Name: Jane Smith, Email: jane.smith@example.com, Phone: +1234567891 ID: 3, Name: Bob Johnson, Email: bob.johnson@example.com, Phone: +1234567892 Specific Customer: ================== ID: 2, Name: Jane Smith, Email: jane.smith@example.com, Phone: +1234567891, Address: 456 Oak Ave, City, State Customer updated successfully! Customer deleted successfully! Remaining Customers: ==================== ID: 1, Name: John Doe, Email: john.doe@example.com ID: 2, Name: Jane Smith, Email: jane.smith@example.com Press Enter to exit... ``` **Note:** You may need to adjust the FireDAC units in the uses clause based on your Delphi version. For newer versions, you might need: ```pascal uses System.SysUtils, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Stan.Connection, FireDAC.Stan.Error, FireDAC.Phys.Intf, FireDAC.Phys.PGSQLDef, FireDAC.Phys.PGSQL, FireDAC.VCLUI.Wait, Data.DB, FireDAC.DApt, FireDAC.DApt.Intf, FireDAC.DatS; ``` Make sure to install the PostgreSQL driver for FireDAC and have a running PostgreSQL instance with proper permissions.