Session Management in Jaggery.js [closed] - mysql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to get some hands on Jaggery frameworks modules and i am facing problems in managing the sessions.
For eg Lets say the user is logging in and then logging out, but even after that when he presses the back button in browser in takes back the user to inner pages.
Here I am destroying the session on clicking Logout like session.invalidate();
but then to the user can traverse back.
Does anyone know how to solve this and manage sessions.
Thanks !

To connect Jaggery to MySQL, you need to download JDBC driver jar to <jaggery>\carbon\repository\components\dropins\ directory.
In MySQL, create new database sodb by typing: mysql> create database sodb.
the example below shows how to create table, insert data in MySQL and view the data using Jaggery.
Create folder sodbmysql in /apps/
Create sodb.jag file in the sodbmysql folder then add this code in the file:
<%
var query1 = "CREATE TABLE example(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT);";
config = {};
var db = new Database("jdbc:mysql://<mysql host>:<port>/<database>", "<mysql_username>", "<mysql_password>", config);
try{db.query(query1); print('Created the table');}
catch(e){print(e.toString());}
finally{db.close();}
%>
Start Jaggery server and go to: localhost:9763/sodbmysql/sodb.jag.
Go to MySQL console> database sodb and enter this to view the table: mysql> show tables;.
To insert the data from Jaggery application, change query to insert data to table:
var query1 ="INSERT INTO example (name, age) VALUES('Jad','34');".
To print in jaggery page, use:
var query1 = "SELECT * FROM example;"
or:
var results = db.query(query3);
print(results);
** For more information, check this link.

Related

DBD::mysql::st execute failed: Query was empty [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
First post. Please bear with me if formatting isn't one-hundred per-cent. Thanks.
I'm in the process of migrating from an older centos server to one with a more up-to-date Debian 9 operating system and I've run into several program incompatibilities... but it hasn't been all bad. I have the full LAMP stack working and "several databases and their pages" up and running just fine. Unfortunately, I've run into a snag. I'll walk through it...
In my www-accessible perl script, I don't include login details in a publically accessible location. I initiate MySQL like so...
use DBI ;
require "connect.cgi" ;
&my_connect();
In the connection file, I have like this...
sub my_connect {
$dsn = "DBI:mysql:dbmydatabase:localhost" ;
$user_name = 'uMyUser';
$user_pass = 'pMyPassword';
$dbh = DBI->connect($dsn, $user_name, $user_pass, { RaiseError => 1} ) ;
return $dbh;
}
So far, so good. I've checked the connection like so...
if(!$dbh){
die "failed to connect to MySQL database DBI->errstr()";
}else{
print("Connected to MySQL server successfully.\n");
}
... and all appears fine and dandy.
I also call for execution from the connection file, like so...
sub Do_SQL {
$sth = $dbh->prepare($SQL);
$rv = $sth->execute;
return $sth;
}
And for the task -- I want to check for the existence of a record in a database. So I set it up and run it...
$SQL = qq/ SELECT EXISTS(SELECT 1 FROM `table1` WHERE `col1` = '$col1') /;
&Do_SQL;
Trouble is, I'm getting an empty query message.
DBD::mysql::st execute failed: Query was empty at connect.cgi line 54.
I have tried a few variations on the query. For example...
$SQL = qq/ SELECT count(*) FROM `table1` WHERE `col1` = '$col1') /;
$SQL = qq/ SELECT `id` FROM `table1` WHERE `col1` = '$col1') /;
$SQL = qq/ SELECT * FROM `table1` /;
... but the result is the same.
I might be tempted to suggest there is some sort of version incompatibility between old and new set up but I have several other pages with similar configuration working fine. A difference might be that the stuff I have working was backed up and restored from previous databases. Whereas this current problem is the first new database I've created from scratch on the new server.
Interestingly, the queries I note above work on the command line. They do not work within the perl script. I've done several searches but can find nothing to point toward a solution. So here I am seeking the benefit and wisdom of more experience than my own.
Thanks for your insights.

Wordpress MySQL database query

I am in the process of setting up a wordpress website that connects to a relay chatroom with an integrated login system, I have connected the database which is working fine however its not allowing the authentication for the users to happen.
The query that i am running in the configuration is:
"SELECT `user_email` AS `email` FROM `wp_users` WHERE `user_login` = #a# AND `user_pass` = MD5(#p#)"
What i am wanting to do is basically have the query check that the user_login exists and then authenticates with the password.
The error that i am currently receiving is as follows:
COMMAND: username#host.host used IDENTIFY and failed to identify to nonexistent account username
This is totally puzzling me now
WordPress doesn't use MD5. So your query is wrong. You can't do it with MySQL only. But you can do it with PHP.
Here is one simple way to achieve it:
Step 1:
Grab class-phpass.php file from WordPress installation (wp-includes directory) and paste it to the neighbour to your request sender file. And use this piece of code there:
require_once("class-phpass.php");
$wp_hasher = new PasswordHash(8, true);
$password='open_password_to_check_here';
$hashed_password='hashed_password_from_mysql'; //select user_pass from wp_users where user_login=#a#;
$result=$wp_hasher->CheckPassword($password,$hashed_password));
//if result is true, then auth is OK.
Alternatively (and the best way) you can use WP REST API, which contains auth process.

How to do multiple queries in Spring Batch (specifically use LAST_INSERT_ID())

I am trying to write a Spring Batch Starter job that reads a CSV file and inserts the records into a MySQL DB. When it begins I want to save the start time in a tracking table, and when it ends, the end time in that same table. The table structure is like:
TRACKING : id, start_time, end_time
DATA: id, product, version, server, fk_trk_id
I am unable to find an example project that does such a thing. I believe this needs to be a Spring Batch Starter project that can handle multiple queries. i.e.
// insert start time
1. INSERT INTO tracking (start_time) VALUES (NOW(6));
// get last inserted id for foreign key
2. SET #last_id_in_tracking = LAST_INSERT_ID();
// read from CSV and insert data into 'data' DB table
3. INSERT INTO data (product, version, server, fk_trk_id) VALUES (mysql, 5.1.42, Server1, #last_id_in_tracking);
4. INSERT INTO data (product, version, server, fk_trk_id) VALUES (linux, 7.0, Server2, #last_id_in_tracking);
5. INSERT INTO data (product, version, server, fk_trk_id) VALUES (java, 8.0, Server3, #last_id_in_tracking);
// insert end time
6. UPDATE tracking SET end_time = NOW(6) WHERE fk_trk_id = #last_id_in_table1;
I'd like sample code and explanation on how to use those queries to multiple tables in the same Spring Batch Starter job.
start of edit section - additional question
I do have an additional question. In my entities I have them set-up to represent the relationships with annotations (i.e #ManyToOne, #JoinColumn)...
In your code, how would I get the trackingId from a referenced object? Let me explain:
My Code (Data.java):
#JsonManagedReference
#ManyToOne
#JoinColumn(name = "id")
private Tracking tracking;
Your code (Data.java):
#Column(name = "fk_trk_id")
private Long fkTrkId;
Your code (JobConfig.java):
final Data data = new Data();
data.setFkTrkId(trackingId);
How do I set the id with "setFkTrkId" when the relationship in my Entity is an object?
end of edit section - additional question
Here is an example app that does what you're asking. Please see the README for details.
https://github.com/joechev/examples/tree/master/csv-reader-db-writer
I have created a project for you as an example. Please refer to https://bigzidane.wordpress.com/2018/02/25/spring-batch-mysql-reader-writer-processor-listener/
This example simply has a Reader/Processor/Writer. The reader will read a CSV file and then process something and then write to database.
And we have a listener to capture StartJob and EndJob. For Start Job, we will insert an entry to DB and then return a generatedId. We will pass the same ID to writer when we stored entries.
Note: I'm sorry I'm reused an example I have already. So it may not match 100% as your question but technically it should be the same.
Thanks,
Nghia

How to generate script in SQL SERVER 2008 R2 without using UI? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi i am using SQL SERVER 2008 R2, can someone please help me to generate a script like create, alter without using UI.
Stored procedures, views, functions etc. can all be scripted from sys.sql_modules as long as they're not encrypted:
SELECT definition
FROM sys.sql_modules
WHERE [object_id] = OBJECT_ID(N'dbo.object_name');
Or if you want to script multiple:
SELECT definition + CHAR(13) + CHAR(10) + 'GO'
FROM sys.sql_modules
WHERE OBJECT_NAME([object_id]) IN (N'name1', N'name2', ...);
Or all:
SELECT '--' + QUOTENAME(OBJECT_SCHEMA_NAME([object_id]))
+ '.' + QUOTENAME(OBJECT_NAME([object_id]))
+ CHAR(13) + CHAR(10) + definition
+ CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10)
FROM sys.sql_modules
WHERE definition IS NOT NULL;
(Of course these are all doomed if you run them in Management Studio and any exceeds the max length of an output string there, ~8K in results to text. But it sounds like you want to consume these elsewhere.)
Note that this won't script the SET settings that were in force at the time the object was created, but you could extend this query to include settings like ANSI_NULLS and QUOTED_IDENTIFIER - which you can get from the same view.
Tables are a little trickier. If you generate the script in SSMS while profiler is running, you will see that it does this through a slew of queries and constructs the create table script within the code (in other words you can't sniff it out). It can be quite complex depending on what options you're using for your table, whether you need to script all foreign keys and dependent objects, etc. For this I would prefer the SMO method highlighted in podiluska's answer.
If you're already using SSMS then I don't understand the purpose of NOT using the generate scripts menu items. You can do so for multiple objects by using Object Explorer Details instead of Object Explorer, if the singleton approach is the problem:
You can use the Scripter class in SQL Management Objects (SMO) to do this.
eg: http://www.mssqltips.com/sqlservertip/1833/generate-scripts-for-database-objects-with-smo-for-sql-server/
Try this:
Create a sproc with following steps.
1.First get all the table names for which you need create table script.
2.loop through each table and get the below info:
select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'tablename'
3.Now in the loop itself try to dynamically populate the create table script.
I wrote an open source command line utility named SchemaZen that does this. It's much faster than scripting from management studio and it's output is more version control friendly. It supports scripting both schema and data.
To generate scripts run:
schemazen.exe script --server localhost --database db --scriptDir c:\somedir
Then to recreate the database from scripts run:
schemazen.exe create --server localhost --database db --scriptDir c:\somedir

mysql insert statement is inserting a blank row instead of the data

I am trying to add new users to my database. For some reason while using the same exact statement in two different scripts and trying to debug, mysql inserts a blank row instead of the actual data if I try to run the query from the php script in which I need it to run from.
On the other hand, when I try to run that exact query in from a random php script, passing the same exact variables (using session variables) to the database, it inserts the data into the database as it should with no problems. I have not idea how to fix such a problem and have been trying for quite a while now. I would greatly appreciate any advice on what I could do to fix this problem.
$usr_email = $_SESSION['email'];
$usr_company_name = $_SESSION['compame'];
$usr_city = $_SESSION['city'];
$usr_state = $_SESSION['state'];
$usr_phone = $_SESSION['phone'];
$usr_password = $_SESSION['password'];
$usr_first = $_SESSION['first'];
$usr_last = $_SESSION['last'];
mysql_query("INSERT INTO users (id, email, compname, city, state, phone, password, first, last)
VALUES('','$usr_email','$usr_company_name','$usr_city','$usr_state','$usr_phone','$usr_password','$usr_first','$usr_last')",$conn);