Jump to content

rynow
 Share

Recommended Posts

romaSQL

This autoIt UDF is built on the concept of Laravel Query & doctrine.
RomaSQL provides a new, comfortable and easy to use way for SQL-queries in autoIt.
Most of the common SQL-queries are supported already and more are coming soon.
All of your support is much appreciated.

Connections
For the connection the object ADODB is used. Therefore the connection string is based on ODBC.
You can also use OLEDB connection strings or other database connections.
In order for this to work your add-ons have to be installed in the function: __4ern_SQL_Connection.
I’d be very glad if you shared your modifications with me.

Currently supported connections
-       MySQL (odbc)
-       Microsoft SQL Server (odbc)
-       SQLite (odbc)
-       Microsoft Access (odbc)

Command reference

$SQL_connect; establishing connection
$SQL_returnType; return a Array or Dictionary ('oDict') Object (Default = Array)
$SQL_setDefaultTable; Default Tablename
$SQL_setDefaultKey; Default Colmn Key (Default = id)
$SQL_debug; if True, show SQL Statment in Console

$SQL_get
$SQL_update
$SQL_delete
$SQL_insertInto
$SQL_take
$SQL_limit
$SQL_table
$SQL_select
$SQL_distinct

$SQL_where
$SQL_orWhere
$SQL_whereBetween
$SQL_whereNotBetween
$SQL_whereIn
$SQL_whereNotIn
$SQL_whereNull
$SQL_whereNotNull
$SQL_having
$SQL_orHaving
$SQL_havingBetween
$SQL_havingNotBetween
$SQL_havingIn
$SQL_havingNotIn
$SQL_havingNull
$SQL_havingNotNull
$SQL_groupBy
$SQL_orderBy

 

Examples

establishing connection

;-----/
; SQLite Connection
;-----/
$SQL_setDatabase('sqlite')
$SQL_connect('C:\project.db')

;-----/
; Access Connection
; Database, User, Password
;-----/
$SQL_setDatabase('access')
$SQL_connect('C:\project.mdb')
;or as Admin
$SQL_connect('C:\project.mdb', '4ern', 'root')

;-----/
; SQLServer Connection
; Database, User, Password, Server, Driver
;-----/
$SQL_setDatabase('sqlserver')
$SQL_connect('myDB', '4ern', 'root', 'localhost')
;or with Driver
$SQL_connect('myDB', '4ern', 'root', 'localhost', 'SQL Server')

;-----/
; MySQL Connection
; Database, User, Password, Server, Driver
;-----/
$SQL_setDatabase('mysql')
$SQL_connect('myDB', '4ern', 'root', 'localhost')
;or with Driver
$SQL_connect('myDB', '4ern', 'root', 'localhost', 'MySQL ODBC 5.2 UNICODE Driver')

 

simple SQL query

$SQL_table('albums')
$aRet = $SQL_get()

if IsArray($aRet ) then
    _ArrayDisplay($aRet )
else
    ConsoleWrite('Keine Ergebnisse' & @LF)
endif

 

Select

$SQL_table('albums')
$SQL_select('id', 'Name', 'Artist', 'Song')

;or pass to an Array
Local $aSelect = ['id', 'Name', 'Artist', 'Song']
$SQL_select($aSelect)

$aRet = $SQL_get()
if IsArray($aRet ) then
    _ArrayDisplay($aRet )
else
    ConsoleWrite('Keine Ergebnisse' & @LF)
endif

where

$SQL_table('albums')
$SQL_select('id', 'Name', 'Artist', 'Song', 'Votes')
$SQL_where('Artist', 'adele')
$SQL_where('Votes', '>=' ,'9')
$SQL_orWhere('Artist', '=' ,'Rag'n'Bone Man')

;or pass to an 2dArray
Local $aSelect = [['Artist','adele'],['Votes', '>=' ,'9']]
$SQL_where($aSelect)

$aRet = $SQL_get()
if IsArray($aRet ) then
    _ArrayDisplay($aRet )
else
    ConsoleWrite('Keine Ergebnisse' & @LF)
endif

 

If you need more examples, then tell me exactly what you need.

I hope you like my UDF and find some use for it.

---

->DONWLOAD romaSQL

 

 

Link to comment
Share on other sites

Interesting coding approach.

 

EDIT:
Added here:
https://www.autoitscript.com/wiki/User_Defined_Functions#Databases_and_web_connections

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I beg to strongly differ.

While this may seem simple to use for SQL newbies, I doubt you can create "serious" SQL queries this way, I mean in real-world applications. Simple queries don't need any of these glue functions and routine non-trivial queries become an horrible mess almost impossible to understand.

Further, it tends to teach newcomers an extremely limited grammar/dialect, instead of exposing the full power of SQL. In my book I call this totally counter-productive and utterly deceptive in the long run.

For instance, imagining you have all Laravel wrapped as AutoIt functions, how would the following (still simple and pretty readable) query translate?

create table T(date integer,test char);
insert into T
values (1,'clim'),(3,'clim'),(7,'amb'),(10,'amb'),(12,'xxx'),
(13,'clim'),(15,'clim'),(20,'clim'),(22,'amb'),(25,'amb');

select
    min(date) as fromdate,
    max(date) as enddate,
    test
from (--get closest preceeding different key
    select
        t.*,
        max(t2.date) as key2
    from
        t
        left join
        t t2
    on t2.date < t.date and t2.test != t.test
    group by t.date
)
group by key2

Nom think of 4 or 8 complex subqueries on 7-table joins...

Laziness never pays long term!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@mLipok  thx

@jchd Thank you for your feedback and forgive me my google Translater english, but I am a different opinion.

On 2.3.2017 at 10:25 AM, jchd said:

While this may seem simple to use for SQL newbies, I doubt you can create "serious" SQL queries this way, I mean in real-world applications. 

 

What are the reputable SQL query and what are simplistic? In my real applications, more than 90% of all SQL queries are rather simple.

On 2.3.2017 at 10:25 AM, jchd said:

Simple queries don't need any of these glue functions and routine non-trivial queries become an horrible mess almost impossible to understand.

I do not think so. I find the laravel prinizip much more clearly and for my SQL queries it is sufficient.

On 2.3.2017 at 10:25 AM, jchd said:

Further, it tends to teach newcomers an extremely limited grammar/dialect, instead of exposing the full power of SQL. In my book I call this totally counter-productive and utterly deceptive in the long run.

For instance, imagining you have all Laravel wrapped as AutoIt functions, how would the following (still simple and pretty readable) query translate?

I agree with you. Newcomers should first learn sql before using these udf. This is similar to Javascript frameworks. But why can not I make life easier if I can sql already.

For subquery I have so far no solution, so you would have to actually execute a $ SQL_raw ('..').

Link to comment
Share on other sites

You're telling me that it is simpler and clearer to write something like

$Sentence.Myself.Subject()
$Sentence.Verb("to be").Present.Person(1)
$Sentence.Negation.Absolute()
$Sentence.Verb("to convince").Participle.Past()
$Sentence.FinalPoint()
ConsoleWrite(SentenceBuild($Sentence) & @LF)

rather than

ConsoleWrite("I am not convinced." & @LF)

That may fit your mood or models but I dare to insist that this is counter-productive.

A non-trivial application can be a typical simple invoicing system, for instance. There you're likely to find a table of clients, a table of delivery locations, a table of invoicing addresses, a table of orders/invoices, a table of items, a table of items ordered (some delivered and some still pending delivery), a table of paiements associated to orders and invoices, and most probably some more tables to fit the real world (suppliers, stock management, ...)

I don't buy the idea that such a common application can use 90% of flat queries.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...