EASY SQL 2024.11.27 (Some Needed Fine-Tune)

HMG Samples and Enhancements

Moderator: Rathinagiri

Post Reply
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

EASY SQL 2024.11.27 (Some Needed Fine-Tune)

Post by Roberto Lopez »

Hi All,

Changes on this Version (2024.11.27)

- Error and Information messages are available in 12 languages now (automatic, based
on hb_langselect() setting).

- a special character can be used to instruct Update and Insert methods to not
quote string values on aColumns array. Default value is '@' but can be
changed via ::cNoQuoteChar class variable.

ie: aCols := { 'price' => '@ price * 1.10' }

- Fixed some methods return values.

- Better documentation.

Last years, for new projects (even local-data ones), I've used protable MariaDB.

It is compact, fast, reliable, secure and requires no installation and configuration.

You can download it at https://mariadb.org/download/ and select 'ZIP file' on
'Package Type'. You can unpack it at any place and run <base_folder>\bin\mysqld.exe.
The default user is root with no password. I'm using 5.5 version since it is enough for my needs.

This class must be considered EXPERIMENTAL.

My idea to start this small library, was to have a wrapper for 'Simple SQL Interface' contribution by Mindaugas Kavaliauskas that I've used for many years.

This wrapper aims to have the following features:

- Handle all possible runtime error situations (bad parameters, connection, SQL syntax, etc.).

- Show all required progress information and error messages to the user.

- Handle simultaneous connections in an easy/intuitive way.


This is a very very basic documentation:

METHODS:


New(): Object Initialization
Returns: SELF (refers to the instance of the class that is being constructed).


Connect(cServer, cUser, cPassword, cDatabase): Connect to a MySql server.
Returns: .T. if connection was successful (.F. otherwise).


Select(cSelect,cWorkArea): cSelect must be a MySql SELECT statement.
A recordset is created with the name specified as cWorkArea.
Returns: .T. if query was successful (.F. otherwise).


Exec(cCommand): Executes a MySql statement.
Returns: .T. if command was successfully executed (.F. otherwise).


Disconnect(): Disconnect from server.
Returns: NIL


CloseAreas(): Close all workareas open with 'Select' method (if any).
Returns: Number of workareas closed.


Insert(cTable, aCols): Insert row. aCols, specifies cColumnname => xData pairs (hash array).
Returns: .T. if command was successfully executed (.F. otherwise).


Delete( cTable, cWhere ): Delete rows based on 'cWhere' condition.
Returns: .T. if command was successfully executed (.F. otherwise).


Update(cTable,cWhere,aCols): Modify rows based on 'cWhere' condition. aCols, specifies
cColumnname => xData pairs (hash array).
Returns: .T. if command was successfully executed (.F. otherwise).


AffectedRows(): Returns the number of rows modified by the last executed
INSERT, UPDATE, or DELETE command.


Destroy(): Set all object variables to NIL, closes all workareas used by
'Select' method (if any) and disconnects.
Returns: NIL


VARIABLES:


lError (Read Only): .T. if an error occured on last operation (.F. otherwise).

cErrorDesc (Read Only): Error description (Empty if no error).

lShowMsgs: Determines if error/progress messages will be shown.

lTrace: When set to .T., a file called 'trace.log' containing last command
executed.

cNoQuoteChar: Set leftmost character indicator to instruct Update and Insert
methods to not quote a character value on aColumns
(cColumnName,xColumnValue) array (default value is '@').



I hope this be useful for someone.


Roberto.
Attachments
easy.sql.2024.11.27.zip
(1.71 MiB) Downloaded 40 times
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
edk
Posts: 981
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: EASY SQL 2024.11.27 (Some Needed Fine-Tune)

Post by edk »

Many, many thx Roberto!
User avatar
Steed
Posts: 429
Joined: Sat Dec 12, 2009 3:40 pm

Re: EASY SQL 2024.11.27 (Some Needed Fine-Tune)

Post by Steed »

Tks
User avatar
serge_girard
Posts: 3223
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: EASY SQL 2024.11.27 (Some Needed Fine-Tune)

Post by serge_girard »

Thanks!
There's nothing you can do that can't be done...
Post Reply