开发者

Why doesn't insert the insert execute? [closed]

开发者 https://www.devze.com 2023-04-01 20:50 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

The database has opened, and the table has created. But I can't Insert record, I'm useing mozilla sqlite storage:

Co开发者_如何学Cmponents.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
let file = FileUtils.getFile("ProfD", ["filef.sqlite"]);
let dbconn = Services.storage.openDatabase(file);
dbconn.executeSimpleSQL('CREATE TABLE IF NOT EXISTS "quicklink" ("id" INTEGER PRIMARY KEY NOT NULL , "name" VARCHAR NOT NULL , "href" VARCHAR NOT NULL )');
var sqlinsert=dbconn.createStatement('INSERT INTO "quicklink" ("name","href") VALUES (:name,:href)');
sqlinsert.params.name = "Something";
sqlinsert.params.href = "URL";
dbconn.close();

I don't get any error(s) in firebug console, or whit the try{}catch(){} statement. Why? What is the problem whit it?


  1. In general, you CANNOT do database access from client-side Javascript.

    There are many exceptions (for example, maybe you're using Node.js on a server, or maybe you're using HP WebOS on a local Sqlite database), but I didn't see anything in your post about your environment or database connectivity.

  2. Assuming you CAN legitimately connect to a database with Javascript in your environment, I don't see where you're executing the prepared SQL statement.

Suggestions:

  1. Please specify the database and database library you're using

  2. Please show us the "execute" statement and corresponding error handler

  3. Please cut/paste any error messages you're getting in the error handler or in the database log.

ADDENDUM:

OK - I'm with you now:

1) You're using the Mozilla "Storage" API.

2) You need to call "executeStatement()" after your "createStatement()".

3) You should also have a "handleError" function.

The documentation and sample code is here:

http://developer.mozilla.org/En/Storage


What database server are you using? If you're using SQL Server, use the profiler to see what command actually gets executed against SQL Server and see what the errors are that it generates.

0

精彩评论

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