Jump to content

ListView and MySql


 Share

Recommended Posts

You know you have to quit when your eyes are blood shot and people are telling you that Man you look beat.... Anyway I'm working with MySql and trying to put a query into a Listview. Problem is with the examples I've been playing with I either get 1. error either BOF or EOF e or 2. the data just simply continues to flow in the listView.

I ran accross an entry somewhere here, I think yesterday, but cant find it which had an example that I beleive will open my eyes to my error.

Anyway heres the problem portion of the script. As you can see Ive tried two ways to get through the issue.

Any guidance is greatly appreciated and will open up the flood gates to this project....

I

Func List()
    $refreshlist = _Query($objDB,"SELECT * FROM Accesslog WHERE Username LIKE 'User.Name' AND Date LIKE '2/29/2012' ORDER BY Computername")
;
         ;  If $refreshlist.EOF Then
         ;  MsgBox(48,"Attention", "The table is empty!")
         ;     $refresh.close
         ;    Return
   ; Endif
        ;$rows = _Query($objDB,"SELECT COUNT(*) Username FROM Accesslog")
        ;$rowcount = $rows.Fields("Username").value
        ;_GUICtrlListView_DeleteAllItems ($ListView)
With $refreshlist
  While Not .EOF
        ; For $i = 1 to $rowcount
  GUICtrlCreateListViewItem($refreshlist.Fields("UserName").value & "|" & $refreshlist.Fields("ComputerName").value & "|" & $refreshlist.Fields("TimeIn").value & "|" & $refreshlist.Fields("Date").value & "|" & $refreshlist.Fields("Serial").value, $ListView)
  ; $refreshlist.MoveNext
  ;   Next
            .Movenext
        WEnd
    EndWith
EndFunc;=> list
Edited by MPHillier

I Break and Fix things... If the surf is up I'm outta here.....

Link to comment
Share on other sites

I'm sorry but I fail to understand where your actual problem is. As I read your code it should perform flawlessly, creating new listview items as rows keep up coming out until query .EOF condition is reached.

BTW beware of SELECT * FROM ... it's a potential pitfall.

In your case you could just use (I don't know the syntax for MySQL string concatenation, but let's assume SQLite syntax instead, which I'm more familiar with)

SELECT username|| '|' || computername || '|' || timein || '|' || date || '|' || serial from ....

This puts the burden of formatting data to the SQL engine (much faster at it than AutoIt multiple invokation of query.something.value) and makes you handle a single field for each result row.

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

jCHD -

I plan to clean up the script and keep at it until it works. I know its something simple....

Thanks for the suggestion - I'll keep plugging away at it more tomorrow... :oops:

Edited by MPHillier

I Break and Fix things... If the surf is up I'm outta here.....

Link to comment
Share on other sites

Had some time to kill so I did some playing around yet I dont have access to the Database until I get to work....

Full test project to this point added.

Also I changed line 75 and used _GUICtrlListView_AddItem. Want to see how this will work.... :oops:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <String.au3>
#include <GuiListView.au3>
#include <mysql.au3>
#Region ### START Koda GUI section ### Form=
;---------------------------------------
Global $objDB, $obQuery, $arArray, $sUserName, $sPassword, $sDomain
Global $ListView, $refreshlist
$objErr = ObjEvent("AutoIt.Error","MyErrFunc")
;---------------------------------------
Local $sServer = "10.100.200.300", $sUsername = "Adam", $sPassword = "vxIcu", $sDatabase = "Doughnut1"
Global $objDB = _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer)
;---------------------------------------
Global $Form1 = GUICreate("Form1", 480, 586, 193, 115)
    $ListView = GUICtrlCreateListView("", 16, 40, 450, 150)
  _GUICtrlListView_AddColumn($ListView, "UserName")
  _GUICtrlListView_AddColumn($ListView, "ComputerName")
  _GUICtrlListView_AddColumn($ListView, "TimeIn")
  _GUICtrlListView_AddColumn($ListView, "Date")
  _GUICtrlListView_AddColumn($ListView, "Serial")
  _GUICtrlListView_SetColumnWidth($ListView, 0, 100)
  _GUICtrlListView_SetColumnWidth($ListView, 1, 100)
  _GUICtrlListView_SetColumnWidth($ListView, 2, 50)
  _GUICtrlListView_SetColumnWidth($ListView, 3, 50)
  _GUICtrlListView_SetColumnWidth($ListView, 4, 50)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
$Button1 = GUICtrlCreateButton("Add", 16, 200, 75, 25, 0)
    $Button2 = GUICtrlCreateButton("Test", 104, 200, 75, 25, 0)
    $Button3 = GUICtrlCreateButton("Close", 192, 200, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Double click to open history", 16, 16, 183, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $nMsg = $Button1
   FillList()
  Case $nMsg = $Button2
   MyTest ()
  Case $nMsg = $Button3
   Close()
EndSwitch
WEnd
Func MyTest ()
$iName = "Bob.Millier"
  $query = _Query($objDB,"SELECT * FROM Accesslog WHERE Username LIKE  '" & $iName  & "' AND Date LIKE '2/29/2312' ORDER BY Computername")
       With $query
           While NOT .EOF
     MsgBox(0,$iName,.Fields("Computername").value & "  " & .Fields("TimeIn").value & "  " & .Fields("Date").value & "  " & .Fields("Serial").value &@CRLF)
            .MoveNext
           WEnd
       EndWith
EndFunc
Func FillList()
  $refreshlist = _Query($objDB,"SELECT * FROM Accesslog WHERE Username LIKE 'michael.hillier' AND Date LIKE '2/29/2312' ORDER BY Computername")
With $refreshlist
   While Not .EOF
_GUICtrlListView_AddItem($refreshlist.Fields("UserName").value & "|" & $refreshlist.Fields("ComputerName").value & "|" & $refreshlist.Fields("TimeIn").value & "|" & $refreshlist.Fields("Date").value & "|" & $refreshlist.Fields("Serial").value, $ListView)
        .Movenext
      WEnd
    EndWith
EndFunc
Func Close()
    _MySQLEnd($objDB)
    Exit
EndFunc;=> close
Func MyErrFunc()
$hexnum=hex($objErr.number,8)
Msgbox(0,"","We intercepted a COM Error!!"    & @CRLF               & @CRLF & _
             "err.description is: " & $objErr.description   & @CRLF & _
             "err.windescription is: " & $objErr.windescription & @CRLF & _
             "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & $objErr.scriptline   & @CRLF & _
             "err.number is: "     & $hexnum               & @CRLF & _
             "err.source is: "     & $objErr.source     & @CRLF & _
             "err.helpfile is: "       & $objErr.helpfile     & @CRLF & _
             "err.helpcontext is: " & $objErr.helpcontext _
            )
;exit
EndFunc;=> MyErrFunc
Edited by MPHillier

I Break and Fix things... If the surf is up I'm outta here.....

Link to comment
Share on other sites

_GUICtrlListView_AddItem wouldn't be a good choice if your listview has more than one column because that only inserts a new row to the first column.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The issue was with my While 1 usage - Changed "Switch" ..... :doh:

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $nMsg = $Button1
   FillList()
  Case $nMsg = $Button2
   MyTest ()
  Case $nMsg = $Button3
   Close()
EndSwitch
WEnd

To "Select"... :bye:

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE ;Or $msg = $exititem
            ExitLoop
  Case $Msg = $Button1
   FillList()
  Case $Msg = $Button2
   MyTest ()
  Case $Msg = $Button3
   Close()
     EndSelect;
WEnd

From here is the obvious - Add clear ListView, options for different queries, Choose ListItem to triger event... and so on....

And we move forward..... :oops:

I Break and Fix things... If the surf is up I'm outta here.....

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...