Changeset 26565
- Timestamp:
- Jan 12, 2010, 2:04:28 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pstamptool.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r26213 r26565 925 925 PXOPT_LOOKUP_BOOL(no_create, config->args, "-no_create", false); 926 926 927 psMetadata *where = psMetadataAlloc(); 928 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 929 PXOPT_COPY_STR(config->args, where, "-imagedb", "imagedb", "=="); 930 PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "=="); 931 932 // start a transaction eraly so it will contain any row level locks 933 if (!psDBTransaction(config->dbh)) { 934 psError(PS_ERR_UNKNOWN, false, "database error"); 935 return false; 936 } 937 927 938 psString query = pxDataGet("pstamptool_pendingdependent.sql"); 928 939 if (!query) { … … 930 941 return false; 931 942 } 943 psString whereClause = psDBGenerateWhereSQL(where, "WHERE"); 944 if (!no_create) { 945 // This will lock the row until the transaction is committed 946 psStringAppend(&query, " %s FOR UPDATE", whereClause); 947 } else { 948 psStringAppend(&query, " %s", whereClause); 949 } 950 psFree(whereClause); 951 psFree(where); 952 932 953 if (!p_psDBRunQuery(config->dbh, query)) { 933 954 psError(PS_ERR_UNKNOWN, false, "database error"); … … 947 968 if (!dep_id) { 948 969 psError(PS_ERR_UNKNOWN, false, "database error"); 970 psFree(output); 949 971 return false; 950 972 } 951 973 printf("%" PRId64 "\n", dep_id); 974 psFree(output); 975 if (!psDBRollback(config->dbh)) { 976 psError(PS_ERR_UNKNOWN, false, "database error"); 977 } 952 978 return true; 953 979 } 954 980 if (no_create) { 981 if (!psDBRollback(config->dbh)) { 982 psError(PS_ERR_UNKNOWN, false, "database error"); 983 return false; 984 } 955 985 return true; 956 986 } 957 987 // no existing dependent that matches, insert one 988 // Since we have multiple processes running jobs we have a 989 // race condition here so that's why we need to lock the table 958 990 959 991 if (!pstampDependentInsert( … … 967 999 no_magic 968 1000 )) { 1001 if (!psDBRollback(config->dbh)) { 1002 psError(PS_ERR_UNKNOWN, false, "database error"); 1003 } 969 1004 psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent"); 970 1005 return false; 971 1006 } 972 1007 1008 if (!psDBCommit(config->dbh)) { 1009 // rollback 1010 if (!psDBRollback(config->dbh)) { 1011 psError(PS_ERR_UNKNOWN, false, "database error"); 1012 } 1013 psError(PS_ERR_UNKNOWN, false, "database error"); 1014 return false; 1015 } 1016 973 1017 psS64 dep_id = psDBLastInsertID(config->dbh); 974 975 1018 printf("%" PRId64 "\n", dep_id); 976 1019
Note:
See TracChangeset
for help on using the changeset viewer.
