Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132

    Using mysql with ODBC connection

    I was using the Lua 5.1 package and it worked good but crashed on app exit.

    Now i'm changing to the ODMC plugin and i'm having some problems
    here is what i have and if you can help please do.

    I do get a good connection using the new ODBC plugin but when i do a query i get a error like "attempt to compare a number with nil".

    tbInfo = ODBC.OpenQuery("SELECT * FROM users ");

    if tbInfo and nRows > 0 then
    for i,v in tbInfo.Data do

    checkuser = tbInfo.Data[i]["username"]
    checkpassword = tbInfo.Data[i]["password"]

    end
    end

    All i did was change this: (old)
    tbInfo = MySQLQueryToTable("SELECT * FROM users ");
    With this: (new)
    tbInfo = ODBC.OpenQuery("SELECT * FROM users ");
    It seems to me that the new line (ODBC) the tbInfo will result in a 0 or 1 and the old line will bring back a table with all the usernames and passwords.

    Please help if you can

    Thanks
    Jean

  2. #2
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    It does not return a table. You need to take a look at the sample he provided. You have to use ODBC.NextRow() to walk through the results.

    Code:
    while (not ODBC.IsEOF()) do
        -- process current row of data
        Grid.SetRowCount("Grid1", row+1);
        for column = 0, numCols-1 do
            data = ODBC.GetColumn(column);
            Grid.SetCellText("Grid1", row, column, data, true);
        end
        row = row + 1;
        -- fetch next row of data
        ODBC.NextRow();
    end
    Dermot

    I am so out of here

  3. #3
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    I probably could return a table with the results of a query, in addition to the current functions already available. The way I implemented the ODBC plugin maps the functions provided in the SDK, where GetFieldValue fetches just one field of the recordset.

    But I could add a new function which returns a table, if there is need for it.

    Ulrich

  4. #4
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    Thanks for the fast reply.

    I was hoping that wasn't the case but i knew it. LOL

    It went from super ez to WHAT? LOL

    all i wanted was a table containing all the usernames and passwords so i could use most of the code i already have but it looks like I'm going to be reading for i while.

    The code you posted is using a grid correct?
    I just need to check if the username and password is correct.


    Thanks for all you help
    Jean

  5. #5
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    upeters

    I was typing my last message when you posted yours.

    That would make my life alot better (i use alot of tables) but check with other people before you add something just for me. I will make mine work someway or other, stuff like this never held me back before.

    Thanks
    Jean

  6. #6
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Quote Originally Posted by jfxwave View Post
    I just need to check if the username and password is correct.
    In this case, you could perform a better query then, instead of fetching the whole table to afterwards check if the password can be verified in some line of the whole resultset. Your approach is slower and causes unnecessary load on the database server...

    In other words, a more appropriate way would be something like this:
    Code:
    -- adapt column names accordingly
    result = ODBC.OpenQuery("SELECT password FROM users WHERE username='" .. somethinghere .. "'");
    if (result ~= 0) then
        -- whoops, something is very wrong here
        error = Application.GetLastError();
        Dialog.Message("ODBC Plugin", "Query failed", MB_OK, MB_ICONSTOP);
        -- close ODBC connection to release memory/handles
        ODBC.CloseConnection();
    else
        -- query executed, but how many results?
        numCols = ODBC.GetNumCols();
        if (numCols < 1) then
            -- no valid result at all, do something appropriate
        else
            -- fetch the result of the query
            data = ODBC.GetColumn(0);
            -- now compare the data retrieved with what the user typed
            -- and do your thing
        end
        -- don't forget housekeeping
        ODBC.CloseConnection();
    end
    Ulrich

  7. #7
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    Thanks allot

    I needed allot more info from the database but with your code i figured it out.


    Thanks again
    Jean

  8. #8
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    I need to correct my former example, as I just saw a mistake in the housekeeping part. While typing the former code, I wrote ODBC.CloseConnection instead of ODBC.CloseQuery. This is better:

    Code:
    ODBC.OpenDSNConnection(DSN, name, password);
    result = ODBC.OpenQuery("SELECT password FROM users WHERE username='" .. somethinghere .. "'");
    if (result ~= 0) then
        -- whoops, something is very wrong here
        error = Application.GetLastError();
        Dialog.Message("ODBC Plugin", "Query failed", MB_OK, MB_ICONSTOP);
    else
        -- query executed, but how many results?
        numCols = ODBC.GetNumCols();
        if (numCols < 1) then
            -- no valid result at all, do something appropriate
        else
            -- fetch the result of the query
            data = ODBC.GetColumn(0);
            -- now compare the data retrieved with what the user typed
            -- and do your thing
        end
        -- don't forget housekeeping
        ODBC.CloseQuery();
    end
    ODBC.CloseConnection();
    Ulrich

Similar Threads

  1. Example: Using MySQL and AMS
    By Jonas DK in forum AutoPlay Media Studio 7.5 Examples
    Replies: 35
    Last Post: 12-26-2009, 06:13 AM
  2. Mysql connection check
    By Teqskater in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 08-20-2007, 01:15 PM
  3. odbc mysql
    By elixyr in forum Setup Factory 7.0
    Replies: 0
    Last Post: 08-04-2005, 12:46 PM
  4. Mysql ODBC dependancy to setupfactory
    By mushaib in forum Setup Factory 7.0
    Replies: 0
    Last Post: 05-27-2005, 05:29 AM
  5. INFO: ODBC Configuration Runtime Notes
    By Support in forum Setup Factory 6.0 Knowledge Base
    Replies: 0
    Last Post: 10-30-2002, 02:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts