0

So this is what I have, I have a SQLite database with 3 tables: status,up_date & users. This database is on the server. I need to run following query on this:

SELECT USR.name, USR.cymer_id, ST.license
FROM
users USR,
status ST,
upd_ate UD
WHERE
UD.upt_id = (select max(p2.upt_id) from upd_ate p2)
AND ST.cymer_id = USR.cymer_id
AND ST.upt_id = UD.upt_id
ORDER BY USR.name

And then display the result on a webpage using HTML.

I was wondering is there any way to do this using java/javascript? or is there any way I can write a java/perl/javascript code to get a xml/text of the output and then display that?

Thanks for your help.

1
  • Oh by the way, if you expect SO to write a chunk of immediately usable code for you, you're in the wrong place. Too many unstated variables for that. Commented Jun 14, 2012 at 19:11

3 Answers 3

2

In Perl, use CGI to generate HTML page and DBI for database query:

#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use DBI;

my $q = CGI->new;
print $q->header, $q->start_html('hello'), '<table>';

my $dbh = DBI->connect("dbi:SQLite:dbname=mydatabase.db", "", "", {});

my $query = <main::DATA>;
my $query_handle = $dbh->prepare($query);
$query_handle->execute();
$query_handle->bind_columns(\my($id, $name, $license));

while($query_handle->fetch()) {
  print "<tr><td>$id</td><td>$name</td><td>$license</td></tr>\n"
}

$query_handle->finish;
$dbh->disconnect;

print '</table>', $q->end_html;

__DATA__
SELECT USR.cymer_id, USR.name, ST.license
FROM users USR, status ST, upd_ate UD
WHERE
  UD.upt_id = (select max(p2.upt_id) from upd_ate p2)
  AND ST.cymer_id = USR.cymer_id
  AND ST.upt_id = UD.upt_id
ORDER BY USR.name 
Sign up to request clarification or add additional context in comments.

10 Comments

If I knew more about the OP's server platform, I'd suggest something in either Java or JavaScript, which the OP clearly prefers.
@SevaAlekseyev - OP has posted his question with more tags and one of them is Perl. Anyway - how would you do it in JavaScript to protect password to access the db?
Haven't noticed, my bad. The question text does not mention Perl.
Got an error ::Error:Can't find string terminator "END_OF_SQL" anywhere before EOF at C:/Users/workspace/License/l1.pl line 19.
@shaleen - Be sure you copied source code correctly, as after your SQL statement, next line is "END_OF_SQL" (see my answer). Also be sure that behind that string on that line there is no other character, not even white space!
|
0

You'll need to write some server-side code for that. There are options for server-side JavaScript: Node.js, classic ASP. Do you know if your Web server supports any of those? Is it a Windows or a *nix server? Is it your home server, your company's server or a hosted one?

In classic ASP with JavaScript, it might look like:

<%@Language="javascript"%>
<html><body><table>
<%
var conn = Server.CreateObject("ADODB.Connection");
conn.Open("Provider=OleSQLite.SQLiteSource;Data Source=PATH_TO_DATABASE");

var rs = conn.Execute("SELECT USR.cymer_id, USR.name, ST.license
    FROM users USR, status ST, upd_ate UD
    WHERE   UD.upt_id = (select max(p2.upt_id) from upd_ate p2)
        AND ST.cymer_id = USR.cymer_id
        AND ST.upt_id = UD.upt_id ORDER BY USR.name");

rs.MoveFirst();
while(!rs.EOF)
{
%>
<tr>
<td><%=Server.HtmlEncode(rs["cymer_id"])%></td>
<td><%=Server.HtmlEncode(rs["name"])%></td>
<td><%=Server.HtmlEncode(rs["license"])%></td>
</tr>
<%
    rs.MoveNext();
}
rs.Close();
conn.Close();

%>
</table></body></html>

You'll need to install the SQLite OLE DB provider. Save as an ASP file, plug the correct database path. On some versions of IIS, you'll have to explicitly enable classic ASP. The Connection and Recordset objects are provided by the Microsoft ADO library.

1 Comment

it's the company's server; I've just started here, I'm not sure if it supports any of those, its a Windows Server; but I also have the database locally available, just so I can make it work. What other variables should I provide?
0

In Perl (on a Unix box) a quick-and-dirty way to do this is:

open( HTML, ">$htmlFile" or die "**error: unable to write to file '$htmlFile', $!\n" );
print HTML `echo "SELECT * FROM holds;" | sqlite3 -html holds_data.db`;
close( HTML );

I haven't experimented using this in Windows.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.