简体   繁体   English

executeSql可以接受命名参数吗?

[英]Can executeSql take named parameters?

I see in examples when executeSql takes several parameters, we use question marks: 我在示例中看到,executeSql带有多个参数时,我们使用问号:

db.transaction(function(tx){
var addedOn = new Date();
tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)",
    [todoText, addedOn],
    html5rocks.webdb.onSuccess,
    html5rocks.webdb.onError);
});

Can executeSql take named parameters? executeSql可以接受命名参数吗?

From that same page : 同一页面上

On November 18, 2010, the W3C announced that Web SQL database is a deprecated specification. 在2010年11月18日,W3C宣布Web SQL数据库已弃用。 This is a recommendation for web developers to no longer use the technology as effectively the spec will receive no new updates and browser vendors aren't encouraged to support this technology. 建议Web开发人员不要再使用该技术,因为该规范将不会获得任何新更新,并且不鼓励浏览器供应商支持该技术。

Also see the big warning at http://www.w3.org/TR/webdatabase 另请参见http://www.w3.org/TR/webdatabase上的重要警告

But to answer your question: As far as I know: no. 但要回答您的问题:据我所知:不。 You could write a 'wrapper' though, replacing your own placeholders with actual values, but I think it won't be worth bothering. 您可以编写一个“包装器”,用实际值替换您自己的占位符,但是我认为这不值得打扰。

Another shot in the dark would by trying to use :foo as placeholder. 尝试在黑暗中进行另一次尝试:foo使用:foo作为占位符。 AFAIK most browsers use(d) SQLite for their webdatabase implementation and, from the top of my head having looked it up , SQLite supports named parameters in the :parametername -form several forms. AFAIK大多数浏览器使用(d)SQLite来实现其Web数据库, 从我的脑海 中查找起 ,SQLite支持:parametername -form几种形式的命名参数。 No idea how you would actually supply values, though I imagine something like [{'foo': 'bar'}, {'baz': 'bat'}] 尽管我想象像[{'foo': 'bar'}, {'baz': 'bat'}]东西,但您不知道如何实际提供价值


EDIT 编辑
I have tried many permutations on your example like this: 我在您的示例中尝试了许多排列,如下所示:

var p = {};
p.aa = todoText;
p.bb = addedOn;

tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (:aa, :bb)",
    p,
    ...
});

Or: 要么:

tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (:aa, :bb)",
    {"aa": todoText, "bb": addedOn},
    ...
});

Or: 要么:

tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (@aa, @bb)",
    {"aa": todoText, "bb": addedOn},
    ...
});

Or: 要么:

tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?aa, ?bb)",
    {"aa": todoText, "bb": addedOn},
    ...
});

...and many more in Chrome 25; ...以及Chrome 25中的更多功能; none of them seem to indicate named parameters are supported. 它们似乎都不表明支持命名参数。 All I can get to work is a simple n th position value to map to an n th parameter position (or index if you will). 我所能做的就是将一个简单的第n个位置值映射到第n个参数位置(或索引,如果可以的话)。

I'm not saying there is absolutely no way, maybe I just couldn't find it or guess the correct way to use it, but I think you're out of luck. 我并不是说绝对没有办法,也许我只是找不到或猜测使用它的正确方法,但我认为您很不走运。 And, again as mentioned in the comments , even should I or someone else get it to work I wouldn't rely on it (because: undocumented , as well as deprecated anyway) and it will probably fail in many (most?) other browsers. 而且,再在评论中提到 ,甚至应该我或别人得到它的工作,我不会依赖它(因为: 无证 ,以及无论如何不建议使用),它会在许多可能会失败(?大多数)其他浏览器。 To be honest: trying to get this to work is a waste of your time. 老实说:设法使它起作用将浪费您的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM