Jump to content
rynow

romaSQL

Recommended Posts

rynow

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

 

 

  • Like 2

Share this post


Link to post
Share on other sites
mLipok

Interesting coding approach.

 

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

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

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 *

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 * 

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) * 

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 *

"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: 2018-03-17

Share this post


Link to post
Share on other sites
jchd

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!

  • Like 1

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)

Share this post


Link to post
Share on other sites
rynow

@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 ('..').

Share this post


Link to post
Share on other sites
jchd

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.

  • Like 1

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)

Share this post


Link to post
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

  • Similar Content

    • Seminko
      By Seminko
      In my recent project I'm downloading a bunch of data, so I decided to store it in a SQLite database. NOTE: I'm using sqlite3_x64.dll
      Everything is working just fine but I'm struggling with getting the Median value. SQLite has an Average function but not a Median one.
      I googled but all of the provided solutions are way above my pay-grade. After some more searching I found 'extension-functions.c' on the SQLite site where Median is included. After almost an hour of struggling I was able to successfully compile it into a DLL.
      So I downloaded @jchd's SQLiteExtLoad.au3 as seen here:
      But I'm getting these errors:
      "Path\SQLiteExtLoad.au3"(21,40) : warning: $g_hDll_SQLite: possibly used before declaration. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "Path\SQLiteExtLoad.au3"(21,40) : error: $g_hDll_SQLite: undeclared global variable. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ So I tried, copying the function to my file and changing the DLL variable ($g_hDll_SQLite) directly to the DLL location (C:\...\.. .dll), but now this error fires
      If __SQLite_hChk($hConn, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) To be honest, I don't know what to use as the $hConn - handle of connection.
      I would appreciate any help, be it getting the median using SQLite queries or getting the DLL extension loaded using AutoIt.
      Thanks, S.
       
      EDIT: well, I suspect the $hConn variable refers to the return value of the _SQLite_Open function. Well, at least now _SQLite_EnableExtensions doesn't give errors. Now I run into problems with _SQLite_LoadExtension, which gives error -1, and extended 1. Apparently the 1 constant is a generic error where other error do not apply.
      BTW, anybody knows whether I need to compile the extension DLL "into" x64 when I use a x64 SQLite? That might be the problem...
       
      EDIT2: I recompiled the dll and tried it using the SQLite3.exe and it works, so I'm confident the extension DLL has been created correctly

    • argumentum
      By argumentum
      ..let's say I store in a mysql column "[1,2,11,12,123]".
      How can I make s query to get all those rows that is 1, or is 12, etc ?
      I'm using  mysqlnd 5.0.11-dev - 20120503 
      Any advise on what technique I should use is welcomed
      Thanks
      PS: ..I'm adding a comma to each end, as in  [,1,2,11,12,123,] and will search with like %,12,% .
      Not pretty but I'm in a hurry and can't come up with a better solution =/
    • AdamUL
      By AdamUL
      I have been testing AutoIt 3.3.14.3 with SQLite, and the Help File examples.  The examples that I have tested are throwing errors or not doing anything.  I have sqlite3.dll, sqlite3_x64.dll, and sqlite3.exe in the directories with the testing script.  I am copying the examples directly from the help file into a test script for testing with no edits.  The _SQLite_GetTable2d example is returning an error ("Library used incorrectly") with each _SQLite_Exec command.  The _SQLite_FastEncode example returns an empty dialog box.  The _SQLite_Exec example only prints out the SQLite version, and nothing else in the SciTE console.  Currently, I'm still searching for what is causing this issue.  I'm on Windows 7 Enterprise 64-bit.  Is anyone else having this issue?  
       
      Adam
       
    • Burgs
      By Burgs
      Greetings,
        I have SQLite setup within my AutoIT program...I'm trying to accomplish what should be a relatively simple task.  I want to be able to return an array of 'table' names for an established database...I believe this might be possible using the '_SQLite_SQLiteExe' command...since it seems to be able to access SQLite schemas...?  The ".tables" command is one of them...if I am not mistaken that command returns a list of all table names in the active database.
        I am attempting the following:
      #include <SQLite.au3> #include <SQLite.dll.au3> Global $hDb, $sIn, $sOut ... $sIn = ".tables" & @CRLF _SQLite_SQLiteExe($hDb, $sIn, $sOut) if @error == 0 Then ;Show Table (using SQLite3.dll) Else if @error == 2 Then ConsoleWrite("ERROR: Sqlite3.exe file not found" & @CRLF) Else ConsoleWrite("ERROR: @error=" & @error & " when calling _SQLite_SQLiteExe" & @CRLF) EndIf ;@error is "2"...OR NOT... EndIf ;@error is "0"...OR NOT... ...   The error being thrown is "ERROR: Sqlite3.exe file not found" ...
        Am I required to have the Sqlite3.exe installed in my directory (i.e. @ScriptsDir)...???  I do not have it in there at present because I did not believe it was necessary with the 'include' calls to "SQLite.au3" and "SQLite.dll.au3"...any advice appreciated.  Thanks in advance. 
      Regards
       
       
       
       
       
       
       
    • sc4ry
      By sc4ry
      Dear all,
      I already have a formula which will select doublicates, but sometimes there might be entries with additional information starting after "-", which I now want to trim away.
      Current formula is:
      Select DISTINCT a.title, a.oid, a.size, a.disk from DB a, DB b where (a.title like b.title and a.oid <> b.oid)" & $ActiveDisks_Filter & " AND (a.comment <> 'Delete' AND b.comment <> 'Delete') Order by a.title ASC, a.size DESC; testwise I want to add a simple solution like left, but afterwards I get an error but I do not know why.
      Select DISTINCT a.title, a.oid, a.size, a.disk from DB a, DB b where (left(a.title,15) like b.title and a.oid <> b.oid) Order by a.title ASC, a.size DESC; Error: near "(": syntax error: Finally I would like to insert intstr to search for "-" but currently I am not able to extend my current code =/
      Thanks a lot for your help.
      EDIT: hey, I managed it, left was not working also it was somehow shown that the tool knowed the comment. I did it now with substr+instr
      (substr(a.title, 1, instr(a.title, ' - '))  
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.