我想将行插入到具有唯一的非自动递增主键的表中.
是否有本机SQL函数来评估最后一个密钥并增加它,或者我必须分两步执行:
key = select max(primary.key) + 1
INSERT INTO dbo.TABLE (primary.key, field1, fiels2) VALUES (KEY, value1, value2)
Run Code Online (Sandbox Code Playgroud) 我的返回 json 文件如下所示:
var data = [{"col1":"value1","col2":"value1","col3":"value1"},{"col1":"value2","col2":"value2","col3":"value2"},{"col1":"value3","col2":"value3","col3":"value3"}];
Run Code Online (Sandbox Code Playgroud)
没有 JSON.stringify 数据看起来像这样:
[对象对象],[对象对象],[对象对象]
但有了它,result.length 不是 5,而是字符串的总字符数,这样我就不能循环了
var result = JSON.stringify(data);
for(i=0; i<result.length; i++){
var transaction = db.transaction([STORE], IDBTransaction.READ_WRITE);
var put = transaction.objectStore(STORE).put(result);
};
Run Code Online (Sandbox Code Playgroud) 我有一个选择框,我想用objectStore中的值自动填充,因为我需要像这样迭代它:"从TABLE中选择COL1,其中COL2 ='myvalue'",这是我的代码:
var db;
var req = indexedDB.open("DB");
req.onsuccess = function (e) {
db = req.result;
var tran = db.transaction("store");
var singleKeyRange = IDBKeyRange.only("myvalue"); //the value I want to reach from COL2
tran.objectStore("store").openCursor(singleKeyRange).onsuccess = function(e) {
var cursor = e.target.result;
if (cursor) {
var opt = document.getElementById("selectbox");
var option = document.createElement("option");
var optionText=document.createTextNode(cursor.value.COL1); //the matching values in COL1
option.appendChild(optionText);
opt.appendChild(option);
cursor.continue();
}
}
};
Run Code Online (Sandbox Code Playgroud)
我已经在objectStore中正确索引了所有值,现在不知道如何通过其他值达到值.
我有一个带有输入框的表单,我想用 IndexedDb objectStore 中的值自动完成它,这适用于两个定位过度的输入框。我在一个简单的数组上工作得很好,但我想让它与来自 objectStore 的值一起工作。为此,我必须将可用的值从事务中取出,以便我可以在自动完成功能中遍历它们。
1- 如何将事务的结果放入其余代码中可用的对象中?
2- 我的循环语法是否可以“results.value.name.length”(名称是我的 objectStore 索引)来处理结果对象?
通过游标获取 IndexedDb 对象:
var results = [];
var openDbRequest = indexedDB.open(DB_NAME);
openDbRequest.onsuccess = function (e) {
var db = e.target.result;
var tran2 = db.transaction("store");
tran2.objectStore("store").openCursor().onsuccess = function(e) {
var cursor = e.target.result;
if (cursor) {
results = cursor;
cursor.continue();
};
};
};
Run Code Online (Sandbox Code Playgroud)
自动完成功能
var auto = "";
var auto_disp = "";
function getName(results) {
var input = document.forms['myform'].name.value;
var len = input.length;
if (input.length) {
for (i=0; i<results.value.name.length; …Run Code Online (Sandbox Code Playgroud) 在同步方法中,我打开游标并向服务器发送Ajax帖子.我需要同时将记录"flag"设置为synchronized.
var transaction = db.transaction([STORE],IDBTransaction.READ_WRITE);
transaction.objectStore(STORE).openCursor().onsuccess = function(e){
var cursor = e.target.result;
if(cursor){
if (cursor.value.flag == "0") {
//sync method
cursor.update(cursor.value.flag = "1") // not working
};
cursor.continue();
};
};
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?