How can I query something with points in variables? - sql

For my site there is a loginsystem where you need to login with your emailadress, but the problem is that my query gives an error when I start writing my emailadress whenever I use a point.
Here is my query:
$sql = "SELECT LeerlingID FROM tblLeerlingen WHERE email = '$myusername' and Wachtwoord = '$mypassword'";

Simply wrap your strings properly:
SELECT LeerlingID FROM tblLeerlingen WHERE email = 'gregoor.maarten.mg#gmail.com' and Wachtwoord = '0dc22c6a909acf658232f6a38e780d7b';

Related

How to use VBA variable for IN 'SourceDB' clause of MS-ACCESS query

I am trying to pass a vba string variable to an IN clause of a SQL statement in the query builder view.
the string is created by the following function:
Public Function GetBackEnd()
If Len(GetBackEnd) = 0 Then GetBackEnd = BackEnd
End Function
backend itself is derived from a dropdown box in userform, there are two entries in a table with two different addresses, one each for the live and developement DB's. The dropdown box sets the "environment" variable upon selection.
Property Get BackEnd() As String
Select Case Environment
Case Is = "Development"
BackEnd = DLookup("VariableValue", "Globals", "Variable= 'TestEnvironment'")
Case Else
BackEnd = DLookup("VariableValue", "Globals", "Variable= 'Backend'")
End Select
End Property
I have tried a couple of variations on the following but get an error each time.
SELECT *
FROM TableName IN 'GetBackEnd()';
I imagine its something simple but after staring at this for so long Ijust can't see it.
thank you.
Generally, you can do what you want - use a function to provide parameter strings.
Public Function GetName() As String
GetName = "foo"
End Function
SELECT * FROM bar WHERE floo = GetName()
But in some parts / cases, you can't use variables. Both IN clauses are among them.
These won't work:
GetInList = "'x', 'y', 'z'"
SELECT * FROM bar WHERE floo IN (GetInList())
and your use-case is not possible either:
GetDbPath = "C:\path\myDb.accdb"
SELECT * FROM bar IN GetDbPath()
You will have to construct the whole SQL on the fly:
Db.QueryDefs("myQuery").SQL = "SELECT * FROM TableName IN '" & GetBackEnd() & "'"
Missing WHERE clause in SQL query? Let's say
SELECT *
FROM TableName
WHERE Name = GetBackEnd;

Empty result on native SQL query on Hibernate

I am trying to develop a simple method to execute sql queries on my application so I can use native sql for certain things.
This is the method I have:
Session session = getReportCsvMgr().getHibernateSession();
session.beginTransaction();
String sql = String.format("select USER_ID from Users where accountid = 'testaaa'");
Object o = session.createSQLQuery(sql).list();
System.out.println(o.toString());
session.close();
I do not get any errors but somehow the object o is empty and the sysout just prints [].
I debugged and the session works. I tested changing the name of the table and indeed it said "table does not exist". I also tried with and update statement, no errors but it does nothing.
Can anybody tell me what I need to do?
Thanks!
Change the line
Object o = session.createSQLQuery(sql).list();
to:
List<Integer> o = session.createSQLQuery(sql).list();
it the USER_ID is integer or to:
List<String> o = session.createSQLQuery(sql).list();
if the USER_ID is string.
Moreover in a query you have not passed params so you can change:
String sql = String.format("select USER_ID from Users where accountid = 'testaaa'");
to simple:
String sql = "select USER_ID from Users where accountid = 'testaaa'";
Either use .uniqueResult() instead of .list() if it only returns one row or change the return type to List<Object[]>

SELECT Syntax error in query. Incomplete query clause

I am trying to make the same sql SELECT for every row.
But, I get a problem in the 'showReader = sqlShowSol.ExecuteReader();'
It says - "Syntax error in query. Incomplete query clause."
Why is it?
-- connection was established before. --
System.Data.OleDb.OleDbCommand sqlShowSol = new System.Data.OleDb.OleDbCommand();
sqlShowSol.Connection = connection;
System.Data.OleDb.OleDbDataReader showReader;
int row = 1;
while (true)
{
sqlShowSol.CommandText = "SELECT Q_A,Content FROM #userName WHERE id = #id;";
sqlShowSol.Parameters.AddWithValue("#userName", userName);
sqlShowSol.Parameters.AddWithValue("#id", row);
showReader = sqlShowSol.ExecuteReader();
|-----------------------------------------------------------------------------------------|
There is more code afterwords...
But I get the problem in the last line I typed here.
Tnx 4 help,
Etay
When you write this:
"SELECT Q_A,Content FROM #userName WHERE id = #id;";
You are using a paramater incorrectly. You are not permitted to use a parameter as the table name. The database engine cannot interpret the #userName reference.

conversion C# to vb.net issue

I am trying to convert C# to vb.net in WCF, the given below is the line of code
var user = from u in users
where u.Key == Id
select u.Value;
On using the conversion tool I get the following result
Dim user = _Where u.Key = Id
but simultaneously I get an error 'End of statement expected'
What am I doing wrong? Can anybody help me out on this?
It's about the same using query syntax really:
Dim users = From user In users
Where user.Key = Id
Select user
The Select is degenerate and if you would prefer, you could use method syntax instead:
users.Where(Function(user) user.Key = ID)
Try this:
Dim user = From u in users
Where u.Key = Id
Select u.Value
Dim user = From u in users Where u.Key = id
Select u.Value
You could also use a lambda.
Dim user = users.FirstOrDefault(Function(u)u.Key = id)
In the Lambda I used FirstOrDefault as you are using a key. This mean when the first record has been found, no extra time is wasted on searching the rest of the collection. it also means user will be null if nothing is found. If it was just a Where clause you would potentially end up with an empty collection.

Expected end of statement error

I have this VB script that is being ran inside a 3rd party app and is throwing the "Expected End of Statement' Error. Here is the code in question. The select statment works fine in SQL server manager studio.
Thanks.
Dim SecurityDB
Set SecurityDB = CreateObject("ADODB.Connection")
Conn = "DRIVER={SQL Server};SERVER=ustcca015s6\Continuum;DATABASE=continuumdb;UID=Andy8796;PWD=xxxx1234;"
SecurityDB.Open Conn
Set EmployeeRS = SecurityDB.Execute "Select count(*) from dbo.personnel where state=1 and lastname not like 'lapt%' and lastname is not NULL and valuelo in (Select ObjectIdLo from area where uiname like 'usmm%' and uiname not like '%gate%') and valuelo <> 1111497912;"
Result = EmployeeRS.GetRows
EmployeeRS.Close
SecurityDB.Close
#RichardTheKiwi posted the answer in the comments section two weeks ago but sadly hasn't added it as an answer in the ... answer section. OK, the Point Pimp[ette] is back tonight, so these questions show up as one step closer to "solved"!
Don't you need a bracket after Execute?
Set EmployeeRS = SecurityDB.Execute("Select count(*) from dbo.personnel where state=1 and lastname not like 'lapt%' and lastname is not NULL and valuelo in (Select ObjectIdLo from area where uiname like 'usmm%' and uiname not like '%gate%') and valuelo <> 1111497912;")