brett_s Posted October 18, 2023 Posted October 18, 2023 This question relates to extracting an SQLite table's row cells from a query using something like the following AutoIt syntax: While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aRow[0], $aRow[1], $aRow[2], $aRow[3]) & @CRLF) WEnd I can extract individual cells by their 0 relative position in the arracy $aRow - for example $aRow[0], $aRow[2] etc. as shown above. However I don't want to do this. I want to be able to extract cell data by their assigned column name - for example EMPLOYEENO, EMPLOYEENAME, EMPLOYEEADDRESS etc. Does anyone know how I can do this? Why do I want to do this? Because if the table structure is subsequently changed and new fields inserted, every existing Autoit script that processes rows using their position in such an array may need to be altered. If the cells are referenced by name instead of number the scripts will not need to be altered.
genius257 Posted October 18, 2023 Posted October 18, 2023 Hi @brett_s You need to use _SQLite_FetchNames to get column names relative to array output position. I don't think anyone has made something to map SQLite fetch to a map object, via the _SQLite_FetchNames yet, but that should be easy to make yourself . To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
jchd Posted October 18, 2023 Posted October 18, 2023 Also don't forget that _you_ specify the columns and their order to get. Using things like "select * from t..." is bad practice. Specifying explicitely the columns and hence their order in the resultset is indeed more verbose but also foolproof. 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 hereRegExp tutorial: enough to get startedPCRE 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)
brett_s Posted October 19, 2023 Author Posted October 19, 2023 Yes, really good suggestion! Many thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now