SMOOTSARA Active Member Licensed User Longtime User Jun 17, 2020 #1 Hello friends? I use the following command to get a specific sequence in the database For example, where the ID is 1 cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE di = 1 ") Click to expand... My question is here I get a list of different IDs as follows List_id => [1,23,467,346,83685,2568,2] Click to expand... What syntax should I use to get these lines in the database? Thanks ?
Hello friends? I use the following command to get a specific sequence in the database For example, where the ID is 1 cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE di = 1 ") Click to expand... My question is here I get a list of different IDs as follows List_id => [1,23,467,346,83685,2568,2] Click to expand... What syntax should I use to get these lines in the database? Thanks ?
D Deleted member 103 Guest Jun 17, 2020 #2 arastoo said: Hello friends? I use the following command to get a specific sequence in the database For example, where the ID is 1 My question is here I get a list of different IDs as follows List_id => What syntax should I use to get these lines in the database? Thanks ? Click to expand... Maybe like this? cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE di = 1 ") B4X: cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE id ='1'") or this ? dim id as int = 1 cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE id =' & id & "'") Upvote 0
arastoo said: Hello friends? I use the following command to get a specific sequence in the database For example, where the ID is 1 My question is here I get a list of different IDs as follows List_id => What syntax should I use to get these lines in the database? Thanks ? Click to expand... Maybe like this? cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE di = 1 ") B4X: cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE id ='1'") or this ? dim id as int = 1 cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE id =' & id & "'")
DonManfred Expert Licensed User Longtime User Jun 17, 2020 #3 It is a mistake to build a query like this. Better is to use parametrized Queries. B4X: cur=sql.ExecQuery2("SELECT * FROM tabel1 WHERE id =?;",Array(1)) Upvote 0
It is a mistake to build a query like this. Better is to use parametrized Queries. B4X: cur=sql.ExecQuery2("SELECT * FROM tabel1 WHERE id =?;",Array(1))
D Deleted member 103 Guest Jun 17, 2020 #4 It is a mistake to build a query like this. Better is to use parametrized Queries. Click to expand... such nonsense! If only the "id" is required, then you don't have to use parametrized queries. Upvote 0
It is a mistake to build a query like this. Better is to use parametrized Queries. Click to expand... such nonsense! If only the "id" is required, then you don't have to use parametrized queries.
makis_best Well-Known Member Licensed User Longtime User Jun 17, 2020 #5 arastoo said: Hello friends? I use the following command to get a specific sequence in the database For example, where the ID is 1 My question is here I get a list of different IDs as follows List_id => What syntax should I use to get these lines in the database? Thanks ? Click to expand... I don't actually understand your question but if you need only a certain number of lines you can use something like B4X: cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE di in (1,23,467,346,83685,2568,2) ") OR cur=sql.ExecQuery2("SELECT * FROM tabel1 WHERE id in (?,?,?,?,?,?,?);",Array(1,23,467,346,83685,2568,2)) if not... and you just need one line then post #2 is your answer. Upvote 0
arastoo said: Hello friends? I use the following command to get a specific sequence in the database For example, where the ID is 1 My question is here I get a list of different IDs as follows List_id => What syntax should I use to get these lines in the database? Thanks ? Click to expand... I don't actually understand your question but if you need only a certain number of lines you can use something like B4X: cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE di in (1,23,467,346,83685,2568,2) ") OR cur=sql.ExecQuery2("SELECT * FROM tabel1 WHERE id in (?,?,?,?,?,?,?);",Array(1,23,467,346,83685,2568,2)) if not... and you just need one line then post #2 is your answer.
SMOOTSARA Active Member Licensed User Longtime User Jun 30, 2020 #6 Hello friends I still haven't been able to solve this problem I get a different list of IDs each time and I have to select them in the database This list may have 3 members exp=>list1=>[34,674,3] Or it may have 20 members exp=>list1=>[34,4,6,7,45,578,123,34,47,547,1,6,2,8,4,2,5,7,4,3,2] How can I introduce the list to Syntax Database? B4X: cur=sql.??????? ("SELECT * FROM tabel1 WHERE id in ??????????????????????? Upvote 0
Hello friends I still haven't been able to solve this problem I get a different list of IDs each time and I have to select them in the database This list may have 3 members exp=>list1=>[34,674,3] Or it may have 20 members exp=>list1=>[34,4,6,7,45,578,123,34,47,547,1,6,2,8,4,2,5,7,4,3,2] How can I introduce the list to Syntax Database? B4X: cur=sql.??????? ("SELECT * FROM tabel1 WHERE id in ???????????????????????
M Mahares Expert Licensed User Longtime User Jul 1, 2020 #7 arastoo said: How can I introduce the list to Syntax Database? Click to expand... Use the stringBuilder (internal library part of B4A) to build the IN operator clause for any list of number of items and then build your query. Here is an example on how to do it: Code: Dim MyList As List MyList.Initialize MyList.AddAll(Array As Int(34,674,3, 76,33,98,4)) Dim sb As StringBuilder sb.Initialize sb.Append( " IN(") For i= 0 To MyList.size -1 Dim f As Int =MyList.Get(i) If i = MyList.Size-1 Then sb.Append($"${f})"$) Else sb.Append($"${f},"$) End If Next Log(sb.ToString) 'displays as example: IN(34,674,3,76,33,98,4) Dim MyInClause As String = sb.ToString cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE id " & MyInClause ) Upvote 0
arastoo said: How can I introduce the list to Syntax Database? Click to expand... Use the stringBuilder (internal library part of B4A) to build the IN operator clause for any list of number of items and then build your query. Here is an example on how to do it: Code: Dim MyList As List MyList.Initialize MyList.AddAll(Array As Int(34,674,3, 76,33,98,4)) Dim sb As StringBuilder sb.Initialize sb.Append( " IN(") For i= 0 To MyList.size -1 Dim f As Int =MyList.Get(i) If i = MyList.Size-1 Then sb.Append($"${f})"$) Else sb.Append($"${f},"$) End If Next Log(sb.ToString) 'displays as example: IN(34,674,3,76,33,98,4) Dim MyInClause As String = sb.ToString cur=sql.ExecQuery("SELECT * FROM tabel1 WHERE id " & MyInClause )
SMOOTSARA Active Member Licensed User Longtime User Jul 1, 2020 #8 Hi Mahares Thank you for your guidance,WORK GOOD Upvote 0