Jump to content

from array to db (SQL)


Jochem
 Share

Recommended Posts

I am trying to put a array into a database, but what am I doing wrong;

I get this error:

!   SQLite.au3 Error
--> Function: _SQLite_Exec
--> Query:    INSERT INTO computer VALUES (WS-C104,'test')
--> Error:    no such column: C104

#include <Array.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

Global $aCompList = _netwerklist(0x1)
Global $host, $hQuery, $aRow, $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup()
_SQLite_Open()
_SQLite_Exec(-1, "Create table computer (comp, user)")
For $host In $aCompList
    _SQLite_Exec(-1, "INSERT INTO computer VALUES (" & $host & ",'test')")
Next

$itest = _SQLite_GetTable2d(-1, "SELECT * FROM computer;", $aResult, $iRows, $iColumns)
_ArrayDisplay($aResult, "Query Result")
_SQLite_Close()
_SQLite_Shutdown()

;===============================================================================
;
; Function Name:    _netwerklist($iSrvType = -1, $sDomain = '')
; Description:      maakt via dllcal de network list (fast)
; Parameter(s):     none
; Requirement(s):   none
; Return Value(s):  Returns een 1d array with computers
; Author(s):        ?????
;
;===============================================================================
Func _netwerklist($iSrvType = -1, $sDomain = '')
    Local $uBufPtr = DllStructCreate("ptr;int;int"), $res[1] = [0], $i
    Local $uRecord = DllStructCreate("dword;ptr"), $iRecLen = DllStructGetSize($uRecord)
    Local $uString = DllStructCreate("char[16]")
    Local $uDomain = DllStructCreate("byte[32]"), $pDomain = 0
    If Not ($sDomain = '' Or $sDomain = '*') Then
        DllStructSetData($uDomain, 1, StringToBinary($sDomain, 2))
        $pDomain = DllStructGetPtr($uDomain)
    EndIf
    Local $ret = DllCall("netapi32.dll", "int", "NetServerEnum", _
            "ptr", 0, "int", 100, _
            "ptr", DllStructGetPtr($uBufPtr, 1), "int", -1, _
            "ptr", DllStructGetPtr($uBufPtr, 2), _
            "ptr", DllStructGetPtr($uBufPtr, 3), _
            "int", $iSrvType, "ptr", $pDomain, "int", 0)
    If $ret[0] Then Return SetError(1, $ret[0], '')
    Local $res[DllStructGetData($uBufPtr, 3) + 1] = [DllStructGetData($uBufPtr, 3)]
    For $i = 1 To DllStructGetData($uBufPtr, 3)
        Local $uRecord = DllStructCreate("dword;ptr", DllStructGetData($uBufPtr, 1) + ($i - 1) * $iRecLen)
        Local $sNBName = DllStructCreate("byte[32]", DllStructGetData($uRecord, 2))
        DllStructSetData($uString, 1, BinaryToString(DllStructGetData($sNBName, 1), 2))
        $res[$i] = DllStructGetData($uString, 1)
    Next
    $ret = DllCall("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($uBufPtr, 1))
    Return $res
EndFunc   ;==>_netwerklist
Link to comment
Share on other sites

You lost the single quotes around the $host value to indicate a literal string. Try:

For $host In $aCompList
    _SQLite_Exec(-1, "INSERT INTO computer VALUES ('" & $host & "','test')")
Next

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...