Password check from the database, what am I doing wrong? - objective-c

-(IBAction)EnterButtonPressed:(id)sender
{
const char *sql = "SELECT AccessCode FROM UserAccess";
double result = ([Password.text doubleValue]);
if(sql == result )
{
NSLog(#"Correct");
}
else {
NSLog(#"Wrong");
}
}

The main thing you're doing wrong is not sending that SQL query to the database. You probably ought to add in some kind of WHERE clause too. And... well, there's quite a lot wrong with that code to be honest.

Related

Where clause using some field is not returning any rows in phonegap

I am finding one funny error but not sure whether that is my mistake or not. Below is my code for phonegap storage application. I have to fetch the records by one field in SELECT Query. If I try without where condition it s working but with where clause it is not working. Anyone have an idea on this?
function setDetailWordList()
{
db.transaction(SetDetailWords);
}
function SetDetailWords(tx)
{
alert("Qiuery executing...");
alert('SELECT * FROM DW_Words WHERE word = "'+word+'"');
tx.executeSql('SELECT * FROM DW_Words where word = "'+word+'"', [], SetDetailWordsSuccess);
}
function SetDetailWordsSuccess(tx,results)
{
alert(results.rows.length);
$('#words').html("").listview('refresh');
for (var i=0; i < results.rows.length; i++)
{
$('#words').append('<li><a><div>'+results.rows.item(i).explanation+'</div></a></li>');
}
$('#words').listview('refresh');
//AddEvents();
}

Else without If error... and I don't know why

The code below is action taken when a button is clicked on a simple form. The problem comes with the one if/else block. The If line is not terminated. The Else line is not terminated. But I have a consistent error that my Else exists without an If. I can't see why. I need someone smarter than me to identify what is going on here.
Thank you in advance!
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FileFilter filter;
filter = new FileNameExtensionFilter("Comma Separated Value files","csv","txt");
JFileChooser chooser;
chooser = new JFileChooser();
chooser.addChoosableFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int showDialog = chooser.showDialog(this, null);
File selectedFile = chooser.getSelectedFile();
String filename;
filename = selectedFile.getAbsolutePath();
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
else
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
}
You are missing the bracket '}' after "jTextField2.setBackground(Color.white);" and else.code is here
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
}
else
{
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The SYNTAX for if-else Block looks like this:-
if {
// statements
} else {
//statements
}
Now if you are having only ONE statement inside the if Or else part then you can afford to skip the curly braces{ } otherwise you surely need to put those curly braces as compiler looks for it can terminate the execution of if statement.
However, it is always recommended to use the braces even if u have only ONE statement inside the if or else part as it improves the readability of the code.
You need to close your "if" and "else" blocks.
Example: if {} else {}.
if (filter.accept(selectedFile)) {
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
} else {
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The if's closing bracket is missing just before the else.

How to configure a timeout for an SQL query in Groovy?

How do I create a timeout for this operation: ?
def db = Sql.newInstance("jdbc:mysql://${mysql_host}:3306/${dbName}",
user, pass, 'com.mysql.jdbc.Driver')
db.eachRow(query) { row ->
// do something with the row
}
I believe the correct way would be something like this:
sql = Sql.newInstance("jdbc:oracle:thin:#localhost:1521:XE", "user",
"pwd", "oracle.jdbc.driver.OracleDriver")
sql.withStatement {
stmt -> stmt.queryTimeout = 10
}
sql.eachRow("select * from someTable", {
println it
} )
of course, this is where I'd used Oracle, but I hope this can give you an idea.
I believe there might not be a general answer, but rather a database/driver-specific answer via parameters to the connection URL.
E.g. for mysql, I think that adding connectTimeout=something&socketTimeout=something might do the trick.

PDO login script won't work

I changed this login script to PDO. Now it passes the username but get's stuck fetchAll line. I need help please. thanks
<?php
session_start();
include_once"includes/config.php";
if (isset($_POST['admin_login'])) {
$admin_user = trim($_POST['admin_user']);
$admin_pw = trim($_POST['admin_pw']);
if ($admin_user == NULL OR $admin_pw == NULL) {
$final_report.="Please complete all the fields below..";
} else {
$check_user_data = $db->prepare("SELECT * FROM `admin`
WHERE `admin_user`='$admin_user'");
$check_user_data->execute();
if ($check_user_data->fetchColumn() == 0) {
$final_report.="This admin username does not exist..";
} else {
$get_user_data = $check_user_data->fetchAll($check_user_data);
if ($get_user_data['admin_pw'] == $admin_pw) {
$start_idsess = $_SESSION['admin_user'] = "".$get_user_data['admin_user']."";
$start_passsess = $_SESSION['admin_pw'] = "".$get_user_data['admin_pw']."";
$final_report.="You are about to be logged in, please wait a few moments...";
header('Location: admin.php');
}
}
}
}
?>
Not checking return value prepare() or execute() for false. You need to check for SQL errors and handle them, stopping the code instead of continuing on blithely.
Not using query parameters in the prepared statement, still interpolating $_POST content into the query unsafely. You're missing the benefit of switching to PDO, and leaving yourself vulnerable to SQL injection attack.
You're storing passwords in plaintext, which is unsafe. See You're Probably Storing Passwords Incorrectly.
Do you really need to SELECT * if you only use the admin_pw column? Hint: no.
PDOStatement::fetchAll() returns an array of arrays, not just one array for a row. Read the examples in the documentation for fetchAll().

gwt html5 database SELECT WHERE AND

iam using http://code.google.com/p/gwt-mobile-webkit/downloads/list?q=label:API-Database
for my project.
there are two textboxes and the user can type in two words.
before these two words will be saved in html database i am looking if these two words are already in the the database saved.
the problem is i dont know how should look like the correct syntax for the
SELECT * FROM words WHERE word1=value1 AND word2=value2.
final String word1 = view.getWord1TextBox().getValue();
final String word2 = view.getWord2TextBox().getValue();
if(Database.isSupported()){
Database db = Database.openDatabase("Words", "1.0", "Word App", 10000);
db.transaction(new TransactionCallback() {
public void onTransactionStart(SQLTransaction tx) {
tx.executeSql("SELECT * FROM words WHERE word1=(?) AND word2=(?)", new Object[]{word1, word2}, new StatementCallback<JavaScriptObject>() {
public void onSuccess(SQLTransaction transaction, SQLResultSet<JavaScriptObject> resultSet) {
System.out.println(" count of rows : "+ resultSet.getRowsAffected());
}
public boolean onFailure(SQLTransaction transaction,SQLError error) {
return false;
}
});
}
public void onTransactionSuccess() {
}
public void onTransactionFailure(SQLError error) {
//setTextMessageLabel("Could not open database", label );
}
});
}
the resultSet.getRowsAffected() is everytime = 0
how should look like the correkt query?
or is there another problem?
please help
How do you know your insert worked?
Does "SELECT * FROM words" return anything?
I use http://code.google.com/p/gwt-mobile-webkit/wiki/DataServiceUserGuide so my syntax is a little different but using the developer tools in chrome you can find the database and run sqlite command in it.
Doing that, this gives me an error
SELECT * from lesson where desc = (summer)
while using quotes works
SELECT * from lesson where desc = ("summer")
SELECT * from lesson where desc = "summer"
You may need to escape it in your code...
"SELECT * FROM words WHERE word1=(\"?\") AND word2=(\"?\")"