0

I have an html page that creates an sqlite database using the openDatabase function.

As I have an existing and large sqlite database, I wonder if I can import it into that web created sqlite database instead of putting my sql code in the transaction.executeSql function repeatedly?

PS: I found this post but no code is shown and the method explained isn't so clear.

Thanks,

Regards

Community
  • 1
  • 1
Zakaria
  • 14,892
  • 22
  • 84
  • 125

1 Answers1

0

I'm not entirely sure if I've understood the question right... but here's something which may or may not answer your question (works in Google Chrome, not sure about anything else):

var db = openDatabase(dbname);
db.transaction(function (query){
   query.executeSql(sql);
});

But you mentioned "web created"... does that mean with a server-side script like PHP? It sounds to me like you have the SQL necessary to import into the database, so why not just create a page with a text box that will let you paste the SQL in, and then post it to the db. If that's in PHP, then it would look something like this:

<form action="index.php" method="POST">
  <textarea name="query"></textarea />
  <input type="text" name="password" />
  <input type="submit />
</form>

<?
if ($_POST['password']=="my super secure password")
{
  $dbname='base';
  $mytable ="tablename";

  $base= new SQLiteDatabase($dbname);
  $base->queryexec($_POST['query']);
}
?>

It shouldn't be too hard to come up with an equivalent in any other language. If you need help, you know where to ask! ;)

Nathan MacInnes
  • 11,033
  • 4
  • 35
  • 50
  • The problem is that I have an HTML page ... I can create an sqlite database with javascript. But, I found no javascript function can read an existing database. – Zakaria Nov 13 '10 at 23:50
  • Not possible. You need some sort of server script to supply the information to the browser. – Hamish Nov 15 '10 at 22:21