830
getStr = sqlite3_mprintf("");
831
for (i=0; getStr && i < count; i++) {
833
newStr = sqlite3_mprintf("a%x", template[i].type);
835
newStr = sqlite3_mprintf("%s, a%x", getStr, template[i].type);
830
for (i=0; i < count; i++) {
831
getStr = sqlite3_mprintf("a%x", template[i].type);
833
if (getStr == NULL) {
834
error = CKR_HOST_MEMORY;
838
newStr = sqlite3_mprintf(GET_ATTRIBUTE_CMD, getStr, table);
837
839
sqlite3_free(getStr);
841
if (getStr == NULL) {
842
error = CKR_HOST_MEMORY;
846
newStr = sqlite3_mprintf(GET_ATTRIBUTE_CMD, getStr, table);
847
sqlite3_free(getStr);
849
if (newStr == NULL) {
850
error = CKR_HOST_MEMORY;
854
sqlerr = sqlite3_prepare_v2(sqlDB, newStr, -1, &stmt, NULL);
855
if (sqlerr != SQLITE_OK) { goto loser; }
856
sqlerr = sqlite3_bind_int(stmt, 1, object_id);
857
if (sqlerr != SQLITE_OK) { goto loser; }
859
sqlerr = sqlite3_step(stmt);
860
if (sqlerr == SQLITE_BUSY) {
861
PR_Sleep(SDB_BUSY_RETRY_TIME);
841
if (newStr == NULL) {
842
error = CKR_HOST_MEMORY;
863
if (sqlerr == SQLITE_ROW) {
864
for (i=0; i < count; i++) {
846
sqlerr = sqlite3_prepare_v2(sqlDB, newStr, -1, &stmt, NULL);
847
sqlite3_free(newStr);
849
if (sqlerr == SQLITE_ERROR) {
850
template[i].ulValueLen = -1;
851
error = CKR_ATTRIBUTE_TYPE_INVALID;
853
} else if (sqlerr != SQLITE_OK) { goto loser; }
855
sqlerr = sqlite3_bind_int(stmt, 1, object_id);
856
if (sqlerr != SQLITE_OK) { goto loser; }
859
sqlerr = sqlite3_step(stmt);
860
if (sqlerr == SQLITE_BUSY) {
861
PR_Sleep(SDB_BUSY_RETRY_TIME);
863
if (sqlerr == SQLITE_ROW) {
867
865
const char *blobData;
869
blobSize = sqlite3_column_bytes(stmt, column);
870
blobData = sqlite3_column_blob(stmt, column);
867
blobSize = sqlite3_column_bytes(stmt, 0);
868
blobData = sqlite3_column_blob(stmt, 0);
871
869
if (blobData == NULL) {
872
870
template[i].ulValueLen = -1;
873
871
error = CKR_ATTRIBUTE_TYPE_INVALID;
876
874
/* If the blob equals our explicit NULL value, then the
877
875
* attribute is a NULL. */
884
882
if (template[i].ulValueLen < blobSize) {
885
883
template[i].ulValueLen = -1;
886
884
error = CKR_BUFFER_TOO_SMALL;
889
887
PORT_Memcpy(template[i].pValue, blobData, blobSize);
891
889
template[i].ulValueLen = blobSize;
895
} while (!sdb_done(sqlerr,&retry));
892
} while (!sdb_done(sqlerr,&retry));
894
sqlite3_finalize(stmt);
898
899
/* fix up the error if necessary */