Hi Friends,
Today I wrote a new demo program using the wonderful EasySQL wrapper to work with the MySQL database. I then generated a description of this demo using ChatGPT and fed this detailed explanation to Grok AI. I was shocked when the AI almost completely restored my original code.
Here is a detailed breakdown and explanation of what this example does by ChatGPT.
This demo is written in Harbour, a modern, open-source version of Clipper/xBase language.
It uses HMG (Harbour MiniGUI) and a custom EasySQL wrapper to work with a MySQL database.
Below is a detailed breakdown and explanation of what this example does:
---
🌐 Purpose:
This is a demo program that:
1. Connects to a MySQL database.
2. Checks if tables customers and orders exist. If not, it creates them and inserts test data.
3. Runs a complex SQL query to retrieve top customer purchases per day within a date range.
4. Displays three editable table views: customers, orders, and the final result.
---
🔧 Key Components and Functions:
1. main_create_table_action() — The main procedure
* Connects to MySQL using constants: _MYSQL_SERVER_, _MYSQL_USER_, etc.
* Creates customers and orders tables (if they don’t exist).
* Populates them with sample data.
* Runs three SELECT queries and shows the results using EDIT EXTENDED TITLE ....
* Disconnects from the DB at the end.
2. IsExistTable( oSql, cTable )
* Executes a query against INFORMATION_SCHEMA.TABLES to check if a table exists.
* Compares the found table name with the expected one (case-insensitively).
* Returns .T. if it exists, otherwise .F..
3. cCreateQuery() / cCreateQuery2()
* Return SQL string for creating the customers and orders tables.
4. cAddQuery() / cAddQuery2()
* Return SQL string for inserting hardcoded records into customers and orders.
5. cGetQuery()
* Returns the final SQL query used to find:
* The customers who made the highest total daily purchase between '2019-02-01' and '2019-05-01'.
✅ Explanation of SQL logic:
* First subquery (daily_totals): Groups all orders per customer per date, sums up total_order_cost.
* Second subquery (max_daily): Gets the maximum daily total cost per day (across all customers).
* Final JOIN: Matches daily totals with the max cost to get the customers who achieved that max.
* Joined with customers to get the first_name.
---
🖥 UI & Display Logic
* Uses EDIT EXTENDED TITLE ... with FIELDENABLED aEdit to show data in a GUI window.
* aEdit := Array( FCount() ) with AFill( aEdit, .F. ) disables field editing (read-only view).
---
✅ Summary
| Component | Purpose |
| ---------------------------- | ---------------------------------------------- |
| SQL():New() | Creates a new database connection object |
| IsExistTable | Checks if a table exists in the current schema |
| cCreateQuery / cAddQuery | Define schema and insert data for customers |
| cCreateQuery2 / cAddQuery2 | Define schema and insert data for orders |
| cGetQuery | Core logic: find top customers per day |
| EDIT EXTENDED | Shows GUI table-like views of the data |
---
💡 Notes:
* This is a great educational demo on SQL + Harbour integration.
---
I have also attached the code recovered using Grok for your review.
I have no words. ;-)))
Thank you for your attention.
Kind regards,
Grigory