Jump to content

MySQL UDFs


cdkid
 Share

Recommended Posts

Ok, got it...it seems COM errors can't be handeled the way we handle other errors

Guess I need to look for some other method to handle the error. :o

I think it may help you to look on the first page at my second or third post. it has a thing to help you track down errors.
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

The MySQL syntax is: SHOW DATABASES;

But then you would need to write a separate COM for it as the MySQL UDFs require database to be specified beforehand. :o

Lemme see what I can come up with.

Edit: Here is the solution:

#include 'MySQL.au3'
$sql = _MySQLConnect($user, $pass, $anydatabase, $host)
$query = "SHOW DATABASES"
$result = _Query($sql, $query)
With $result
    While NOT .EOF
    MsgBox(0, '', .Fields("Database").value)
    .MoveNext
    WEnd
EndWith
_MySQLEnd($sql)

Remember this will only show those databases that $user has privileges to see.

Edited by kclteam

I believe we should all pay our tax with a smile. I tried - but they wanted cash!

Link to comment
Share on other sites

UPDATE:

added _GetDBNames

Returns an array

$array[0] = DB Count

$array[n] = Nth database name.

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

wait, then how do you select a different database if the connection makes you select one already?

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

I'm working on functions to change the connection string right now, it'll be just a li'l bit longer.

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

UPDATE:

Added _ChangeCon()

USAGE:

$m = _MySQLConnect($username, $password, $database, $server)
$m = _ChangeCon($m, '','',$newdatabase, '', $newserver);This will change the connection to a new server
;and database, but keep the same driver & username/password

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

DEAD END ALERT!!! ( i figured this would be the best place to ask this)

I'm writing my functions in COM and it works great with autoit, so here's the au3 code

Dim $cdobj, $m, $l, $q
$l[0] = "this"
$l[1] = "is"
$m[0] = "a"
$m[1] = "test"
$cdobj = ObjCreate("CdSQL.MySQL")
$q = $cdobj.addrecord("sometable", $m, $l)
msgbox (0, '', $q);I have addrecord returning the SQL command for debugging purposes

Now, all that works great, but this doesnt (vbscript code)

dim cdobj, m, l, q
l = Array("this", "is")
m = Array("a","test")
set cdobj = WScript.CreateObject("CdSQL.MySQL")
q = cdobj.addrecord("sometable", m, l)
msgbox q

I get an "Invalid argument" error at "q = cdobj.addrecord..."

but this works fine

dim cdobj, q
set cdobj = WScript.CreateObject("CdSQL.MySQL")
q = cdobj.addrecord("sometable", array("this","is"), array("a","test"))
msgbox q

And here is the source code for my AddRecord function (set up for debugging, not executing query yet.)

Public Function AddRecord(ByVal table As Object, ByVal Col() As Object, ByVal Value() As Object) As Object
        'AddRecord overload #1 --> Variant array for Columns
        'Variant array for  Values
        Dim str As Object, i As Integer
        str = "INSERT INTO " & table & "("
        For i = 0 To UBound(Col, 1)
            If i = UBound(Col, 1) Then
                str = str & Col.GetValue(i)
            Else
                str = str & Col.GetValue(i) & ","
            End If
        Next
        i = 0
        str = str & ") VALUES("
        For i = 0 To UBound(Value, 1)
            If i = UBound(Value, 1) Then
                str = str & Value.GetValue(i)
            Else
                str = str & Value.GetValue(i) & ","
            End If
        Next
        str = str & ");"
        Return str
    End Function

If anyone could help me figure out the problem with this, i'd really appriciate it.

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

Heh, I'm developing it for what ever you want to use it for, so I guess. But dont try to take credit for it or i will hunt you down!!!!!! lol anyway, yeah sure.

--Still wondering about this COM problem in my last post....

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

Just a quick question:

How can I add an error check for the ODBC driver's existance in the script?

The @error macro didn't work after the _MySQLConnect function. I think you should add such functionality in your UDF.

Thanks in advance,

Edited by erebus
Link to comment
Share on other sites

Can you post the registry key where that is so i can add it to the _MySQLConnect UDF?

Edit: Also, I fixed the problem in my post earlier, for it to work with VBScript i had to remove the () from the param names.

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

@cdkid: I saw in your UDF that you have @error support. However it doesn't work (and I don't know why).. Can you tell?

Edit: about the registry key, I think he means the 'HKLM\Software\MySQL AB\MySQL Connector/ODBC 3.51' one. Also 'HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers' would do the job. However I don't like this method much.. I prefer the @error macro instead.

Edited by erebus
Link to comment
Share on other sites

Well, what I'd do is check the registry key & set @ERROR if it doesnt contain MySQL ODBC Connector

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

[uPDATE]

If the driver is not found _MySQLConnect should set @Error to 2 and return 0.

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

that's becoz the error is COM error...so script stops abruptly thereafter...no @error is set watsoever...

i read it in the help files...but not quite sure if my concepts of COM are clear...

I use COM error handeler which cdkid has mentioned in 3rd or 4th post in the very first page of this thread...and I guess that's the only way :)

P.S.: I was talking about

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Scan the content of this key for MySQL ODBC Connector.

Edit: There is a thread in the forums about a script which checks for all installed softwares on a compute. I use that actually.

Edited by kclteam

I believe we should all pay our tax with a smile. I tried - but they wanted cash!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...