Jump to content

If $SQL[$z][1] = "a" Or "b" Or "c" Or "d" Or"e" Or "f" then


 Share

Recommended Posts

It seems because I do not have proper education in this field i make big beginner mistakes

 

my 2d array has 40.000 items from 2 tables which needs to combined and all works flawless

 

but i want to filter out for lets say 25 pre defined names , which i prefer to type out

i am trying to do the follow but it does not work

If $SQL[$z][1] = "abb" Or "bbb" Or "cbb" Or "dbb" Or "ebb" Or "fbb"  then
        If $CSQL[$z][5] = "T" Then
                     $lineskip = True
(code)
MsgBox(0, "", $z & "True")
elseif
If $CSQL[$z][5] = "F" Then
$lineskip = False
(code)
MsgBox(0, "", $z & "False" )
endif

How to make this work? and what is best practice? a tiny bit of background would also help me a lot

I am very sorry for such a horrible starters question

Edited by butterfly
Link to comment
Share on other sites

Either something like this or use Switch for multiple values:

If $SQL[$z][1] = "abb" Or $SQL[$z][1] = "bbb" Or $SQL[$z][1] = "cbb" Or $SQL[$z][1] = "dbb" Or $SQL[$z][1] = "ebb" Or $SQL[$z][1] = "fbb" Then
    If $CSQL[$z][5] = "T" Then
        $lineskip = True
        ; (code)
        MsgBox(0, "", $z & "True")
    ElseIf $CSQL[$z][5] = "F" Then
        $lineskip = False
        ; (code)
        MsgBox(0, "", $z & "False")
    EndIf
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

Someone will undoubtedly be along to tell me my regex-fu sucks (which it does), but I would think you could do something like this if you are only trying to match a few patterns:

#include <Array.au3>

Local $SQL[6][2]
    $SQL[0][0] = "5"
    $SQL[0][1] = ""
    $SQL[1][0] = "Line 1"
    $SQL[1][1] = "aaa"
    $SQL[2][0] = "Line 2"
    $SQL[2][1] = "bbb"
    $SQL[3][0] = "Line 3"
    $SQL[3][1] = "fff"
    $SQL[4][0] = "Line 4"
    $SQL[4][1] = "ggg"
    $SQL[5][0] = "Line 5"
    $SQL[5][1] = "hhh"


For $i = 1 To $SQL[0][0]
    If StringRegExp($SQL[$i][1], "abb|bbb|cbb|dbb|ebb|fbb") Then
        MsgBox(0, $SQL[$i][0], "Matches pattern, do something here.")
    Else
        MsgBox(0, $SQL[$i][0], "Doesn't match pattern, do something else")
    EndIf
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

or something like this

$string = '|abb|bbb|cbb|dbb|ebb|fbb|'
If StringInStr($string, '|' & $SQL[$z][1] & '|') Then
    If $CSQL[$z][5] = "T" Then
        $lineskip = True
        ; (code)
        MsgBox(0, "", $z & "True")
    ElseIf $CSQL[$z][5] = "F" Then
        $lineskip = False
        ; (code)
        MsgBox(0, "", $z & "False")
    EndIf
EndIf

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

A Switch example:

Switch $SQL[$z][1]
    Case "abb", "bbb", "cbb", "dbb", "ebb", "fbb"
        If $CSQL[$z][5] = "T" Then
            $lineskip = True
            ; (code)
            MsgBox(0, "", $z & "True")
        ElseIf $CSQL[$z][5] = "F" Then
            $lineskip = False
            ; (code)
            MsgBox(0, "", $z & "False")
        EndIf
    Case Else
        MsgBox(0, "", "Not Found")
EndSwitch

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

 

my 2d array has 40.000 items from 2 tables which needs to combined and all works flawless

but i want to filter out for lets say 25 pre defined names , which i prefer to type out

This attracts two sideways remarks which may not be valid but who knows?

First you can join tables in SQL queries even if tables come from two DBs, in which case you can attach the second one to the first (you may be using that already).

Second, rather than filtering out unwanted data from a large dataset you can specify where conditions to avoid getting them in the resultset. Again this may not be valuable in your specific use case.

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

butterfly,

An example of what jchd is alluding to.  Better to let the DB engine do the work for you...

#include <sqlite.au3>

;---------------------------------------------------------------------------------------
; initialize SQLite, open DB and declare some common variables
;---------------------------------------------------------------------------------------

_SQLite_Startup()

If @error Then
    ConsoleWrite('error loading sqlite.dll' & @LF)
    Exit
EndIf

Local $hDB = _SQLite_Open(':memory:')

If @error Then
    ConsoleWrite('Unable to open DB' & @LF)
    _exit()
EndIf

OnAutoItExitRegister("_exit")

Local $ret, $rows, $nbrows, $nbcols, $sqlstr

;---------------------------------------------------------------------------------------
; create two tables and load some data
;---------------------------------------------------------------------------------------

$ret = _SQLite_Exec($hDB, 'create table if not exists T1 (Col1, Col2, Col3, Col4); create table if not exists T2 (Col1,Col2);')
If $ret <> $SQLITE_OK Then
    MsgBox(0, 'ERROR', 'Create table error')
    _exit()
EndIf

$sqlstr = _
        'insert into T1 values("abb","","","");' & _
        'insert into T1 values("bbb","","","");' & _
        'insert into T1 values("cbb","","","");' & _
        'insert into T1 values("dbb","","","");' & _
        'insert into T1 values("ebb","","","");' & _
        'insert into T1 values("fbb","","","");' & _
        'insert into T2 values("abb","T");' & _
        'insert into T2 values("bbb","T");' & _
        'insert into T2 values("cbb","F");' & _
        'insert into T2 values("dbb","T");' & _
        'insert into T2 values("ebb","T");' & _
        'insert into T2 values("fbb","F");'

$ret = _SQLite_Exec($hDB, $sqlstr)

If $ret <> $SQLITE_OK Then
    MsgBox(0, 'ERROR', 'Insert table error')
    _exit()
EndIf

;  the "where...in" clause uses the DB engine to filter the data.

$sqlstr = ' select T1.Col1, T2.Col2 from T1, T2 ' & _
        '      where T1.Col1 = T2.Col1 and T1.Col1 in ("cbb","dbb");'

$ret = _SQLite_GetTable2d($hDB, $sqlstr, $rows, $nbrows, $nbcols)

If @error Then
    ConsoleWrite("!>  Error getting Data" & @LF)
    _exit()
EndIf

_ArrayDisplay($rows)

Func _exit()
    _SQLite_Close()
    _SQLite_Shutdown()
    Exit
EndFunc   ;==>_exit

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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