In the example to DBGetRecordSet(), Sealeopard uses two FOR loops to evaluate the results. I'd like to just get the LATEST result and tried to use ubound() to do it (after reading the function it sounded like it would've worked). But it KiX kicked it back and I was wondering if you could tell me if the way I did it was wrong or if there's another way to get the single, latest record from the DB?
Example with Sealeopard's "example":
Code:
;START MODIFICATIONS TO NTDOC'S SCRIPT TO WRITE THE GATHERED INFORMATION TO A MYSQL DATABASE
;DIM OBJECTS BY CATEGORY
DIM $objConn
DIM $compSQL,$processSQL
DIM $cid,$ProcessName,$ProcessID,$ProcessPath
DIM $queryForCID,$recordset,$retcode,$row,$column
;VARIABLES FOR DATABASE CONNECTIVITY
$ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;"
$objConn = DBConnOpen($ConnDSN)
? "Error @ERROR: @SERROR"
sleep 1
;STRIP BACKSLASHES OUT OF THE FIELDS AND WRITE THE COMPUTER SPECIFIC INFORMATION TO THE DATABASE
$LogonServer = Replace('$LogonServer','\','|')
$SystemUpTime = Replace('$SystemUpTime','\','|')
$compSQL = "INSERT INTO computers(Name,LastLogonTime,LastLogonDate,LogonServer,Domain,CurrentIP,MACAddress,SerialNumber,OSType,OSServicePack,OSInstallDate,OSBuild,OSRole,ProductKey,RegisteredOwner,RegisteredOrganization,ProcessorType,ProcessorSpeed,MemorySize,SystemType,ChassisType,BIOSName,SMBIOSVersion,BIOSVersion,BIOSManufacturer,Uptime,ScriptRunTime)
VALUES('$HostName','$Time','$Date','$LogonServer','$DomainMemberOf','$CurrentIP','$MAC','"+$MyBIOSInfo[3]+"','$ProdType','"+$CurrentOS[3]+"','$InstallDate','"+$CurrentOS[4]+"','"+$CurrentOS[2]+"','"+$CurrentOS[8]+"','"+$CurrentOS[6]+"','"+$CurrentOS[7]+"','$CPU','$Mhz','$Ram','"+$ST[0]+"','"+$ST[1]+"','"+$MyBIOSInfo[0]+"','"+$MyBIOSInfo[2]+"','"+$MyBIOSInfo[1]+"','"+$MyBIOSInfo[4]+"','$SystemUpTime','$ScriptRunTime')"
$ = DBExecuteSQL($objConn,$compSQL)
? "Error @ERROR: @SERROR"
;QUERY THE DATABASE FOR THE CID OF THE COMPUTER THAT WAS JUST ENTERED INTO THE DATABASE
$queryForCID = "SELECT cid FROM computers WHERE Name='$HostName' AND MACAddress='$MAC'"
$recordset = DBGetRecordset($objConn,$queryForCID)
$retcode = DBConnClose($objConn)
for $row=0 to ubound($recordset,1)
for $column=0 to ubound($recordset,2)
? 'Field ='+$recordset[$row,$column]
next
next
My attempt modify Sealeopard's example to just get the most recent record:
Code:
;START MODIFICATIONS TO NTDOC'S SCRIPT TO WRITE THE GATHERED INFORMATION TO A MYSQL DATABASE
;DIM OBJECTS BY CATEGORY
DIM $objConn
DIM $compSQL,$processSQL
DIM $cid,$ProcessName,$ProcessID,$ProcessPath
DIM $queryForCID,$recordset,$retcode,$latestRecord
;VARIABLES FOR DATABASE CONNECTIVITY
$ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;"
$objConn = DBConnOpen($ConnDSN)
? "Error @ERROR: @SERROR"
sleep 1
;STRIP BACKSLASHES OUT OF THE FIELDS AND WRITE THE COMPUTER SPECIFIC INFORMATION TO THE DATABASE
$LogonServer = Replace('$LogonServer','\','|')
$SystemUpTime = Replace('$SystemUpTime','\','|')
$compSQL = "INSERT INTO computers(Name,LastLogonTime,LastLogonDate,LogonServer,Domain,CurrentIP,MACAddress,SerialNumber,OSType,OSServicePack,OSInstallDate,OSBuild,OSRole,ProductKey,RegisteredOwner,RegisteredOrganization,ProcessorType,ProcessorSpeed,MemorySize,SystemType,ChassisType,BIOSName,SMBIOSVersion,BIOSVersion,BIOSManufacturer,Uptime,ScriptRunTime)
VALUES('$HostName','$Time','$Date','$LogonServer','$DomainMemberOf','$CurrentIP','$MAC','"+$MyBIOSInfo[3]+"','$ProdType','"+$CurrentOS[3]+"','$InstallDate','"+$CurrentOS[4]+"','"+$CurrentOS[2]+"','"+$CurrentOS[8]+"','"+$CurrentOS[6]+"','"+$CurrentOS[7]+"','$CPU','$Mhz','$Ram','"+$ST[0]+"','"+$ST[1]+"','"+$MyBIOSInfo[0]+"','"+$MyBIOSInfo[2]+"','"+$MyBIOSInfo[1]+"','"+$MyBIOSInfo[4]+"','$SystemUpTime','$ScriptRunTime')"
$ = DBExecuteSQL($objConn,$compSQL)
? "Error @ERROR: @SERROR"
;QUERY THE DATABASE FOR THE CID OF THE COMPUTER THAT WAS JUST ENTERED INTO THE DATABASE
$queryForCID = "SELECT cid FROM computers WHERE Name='$HostName' AND MACAddress='$MAC'"
$recordset = DBGetRecordset($objConn,$queryForCID)
$retcode = DBConnClose($objConn)
$latestRecord = ubound($recordset)
? $latestRecord
While this works, it returns the total number of rows, not the information from my query about the latest row. Can anyone put me in the right direction?