开发者

Injecting sql scripts from an SQL file into sqlite database in javascript

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.executeSq开发者_高级运维l function repeatedly?

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

Thanks,

Regards


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! ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜