本文整理汇总了C++中IDBTransaction::GetOrCreateObjectStore方法的典型用法代码示例。如果您正苦于以下问题:C++ IDBTransaction::GetOrCreateObjectStore方法的具体用法?C++ IDBTransaction::GetOrCreateObjectStore怎么用?C++ IDBTransaction::GetOrCreateObjectStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDBTransaction
的用法示例。
在下文中一共展示了IDBTransaction::GetOrCreateObjectStore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: autoRemove
//.........这里部分代码省略.........
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
nsresult rv = params.Init(aCx, &aOptions);
NS_ENSURE_SUCCESS(rv, rv);
// Get keyPath
jsval val = params.keyPath;
if (!JSVAL_IS_VOID(val) && !JSVAL_IS_NULL(val)) {
if (!JSVAL_IS_PRIMITIVE(val) &&
JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(val))) {
JSObject* obj = JSVAL_TO_OBJECT(val);
jsuint length;
if (!JS_GetArrayLength(aCx, obj, &length)) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (!length) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
keyPathArray.SetCapacity(length);
for (jsuint index = 0; index < length; index++) {
jsval val;
JSString* jsstr;
nsDependentJSString str;
if (!JS_GetElement(aCx, obj, index, &val) ||
!(jsstr = JS_ValueToString(aCx, val)) ||
!str.init(aCx, jsstr)) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (!IDBObjectStore::IsValidKeyPath(aCx, str)) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
keyPathArray.AppendElement(str);
}
NS_ASSERTION(!keyPathArray.IsEmpty(), "This shouldn't have happened!");
}
else {
JSString* jsstr;
nsDependentJSString str;
if (!(jsstr = JS_ValueToString(aCx, val)) ||
!str.init(aCx, jsstr)) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (!IDBObjectStore::IsValidKeyPath(aCx, str)) {
return NS_ERROR_DOM_SYNTAX_ERR;
}
keyPath = str;
}
}
}
if (databaseInfo->ContainsStoreName(aName)) {
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
}
if (params.autoIncrement &&
((!keyPath.IsVoid() && keyPath.IsEmpty()) || !keyPathArray.IsEmpty())) {
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
nsRefPtr<ObjectStoreInfo> newInfo(new ObjectStoreInfo());
newInfo->name = aName;
newInfo->id = databaseInfo->nextObjectStoreId++;
newInfo->keyPath = keyPath;
newInfo->keyPathArray = keyPathArray;
newInfo->nextAutoIncrementId = params.autoIncrement ? 1 : 0;
newInfo->comittedAutoIncrementId = newInfo->nextAutoIncrementId;
if (!databaseInfo->PutObjectStore(newInfo)) {
NS_WARNING("Put failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
// Don't leave this in the hash if we fail below!
AutoRemoveObjectStore autoRemove(databaseInfo, aName);
nsRefPtr<IDBObjectStore> objectStore =
transaction->GetOrCreateObjectStore(aName, newInfo);
NS_ENSURE_TRUE(objectStore, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
nsRefPtr<CreateObjectStoreHelper> helper =
new CreateObjectStoreHelper(transaction, objectStore);
nsresult rv = helper->DispatchToTransactionPool();
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
autoRemove.forget();
objectStore.forget(_retval);
return NS_OK;
}