Changeset 4389
- Timestamp:
- Jun 24, 2005, 3:16:50 PM (21 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
dataIO/psDB.c (modified) (4 diffs)
-
dataIO/psFileUtilsErrors.dat (modified) (1 diff)
-
dataIO/psFileUtilsErrors.h (modified) (2 diffs)
-
db/psDB.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataIO/psDB.c
r4382 r4389 12 12 * @author Joshua Hoblitt 13 13 * 14 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-06-2 4 21:29:41$14 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-06-25 01:16:50 $ 16 16 * 17 17 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 783 783 { 784 784 char *query; 785 785 psS64 rows = 0; 786 787 // Verify database is not NULL 788 if(dbh == NULL) { 789 psError(PS_ERR_UNEXPECTED_NULL, true, PS_ERRORTEXT_psDB_INVALID_PSDB); 790 return -1; 791 } 792 793 // Create SQL statement string 786 794 query = psDBGenerateDeleteRowSQL(tableName, where); 787 795 if (!query) { 788 796 psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed."); 789 790 797 return -1; 791 798 } 792 799 800 // Run SQL query 793 801 if (!p_psDBRunQuery(dbh, query)) { 794 802 psError(PS_ERR_UNKNOWN, false, "Delete failed."); 795 796 803 mysql_rollback(dbh->mysql); 797 798 804 psFree(query); 799 800 805 return -1; 801 806 } 802 803 807 psFree(query); 804 808 805 if (!where) { 806 // we truncated the table so mysql_affected_rows() won't work 807 return 1; 808 } 809 // Get the number of affected row for the delete command 810 rows = (psS64)mysql_affected_rows(dbh->mysql); 809 811 810 812 // point of no return 811 813 mysql_commit(dbh->mysql); 812 814 813 return (psS64)mysql_affected_rows(dbh->mysql);815 return rows; 814 816 } 815 817 … … 1138 1140 if (!where) { 1139 1141 psStringAppend(&query, "TRUNCATE TABLE %s", tableName); 1140 1141 1142 return query; 1142 1143 } 1143 1144 1145 // Generate where SQL substring 1144 1146 whereSQL = psDBGenerateWhereSQL(where); 1145 1147 if (!whereSQL) { 1146 psError(PS_ERR_UNEXPECTED_NULL, false, "SQL substring generation failed.");1147 1148 return NULL;1149 } 1150 1148 psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_SQL_SUBSTR_FAIL); 1149 return NULL; 1150 } 1151 1152 // Complete delete SQL command string 1151 1153 psStringAppend(&query, "DELETE FROM %s %s", tableName, whereSQL); 1152 1154 psFree(whereSQL); … … 1163 1165 if (!where) { 1164 1166 psError(PS_ERR_BAD_PARAMETER_NULL, true, "where param may not be NULL."); 1165 1166 1167 return NULL; 1167 1168 } -
trunk/psLib/src/dataIO/psFileUtilsErrors.dat
r4382 r4389 72 72 psDB_UPDATE_ROW_FAIL Update row SQL generate fail: values and where params may not be NULL. 73 73 psDB_SQL_SUBSTR_FAIL SQL substring generation failed. 74 psDB_WHERE_SUBSTR_FAIL WHERE parameter my not be NULL. 74 75 # 75 76 -
trunk/psLib/src/dataIO/psFileUtilsErrors.h
r4382 r4389 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-06-2 4 21:29:41$9 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-06-25 01:16:50 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 91 91 #define PS_ERRORTEXT_psDB_UPDATE_ROW_FAIL "Update row SQL generate fail: values and where params may not be NULL." 92 92 #define PS_ERRORTEXT_psDB_SQL_SUBSTR_FAIL "SQL substring generation failed." 93 #define PS_ERRORTEXT_psDB_WHERE_SUBSTR_FAIL "WHERE parameter my not be NULL." 93 94 //~End 94 95 -
trunk/psLib/src/db/psDB.c
r4382 r4389 12 12 * @author Joshua Hoblitt 13 13 * 14 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-06-2 4 21:29:41$14 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-06-25 01:16:50 $ 16 16 * 17 17 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 783 783 { 784 784 char *query; 785 785 psS64 rows = 0; 786 787 // Verify database is not NULL 788 if(dbh == NULL) { 789 psError(PS_ERR_UNEXPECTED_NULL, true, PS_ERRORTEXT_psDB_INVALID_PSDB); 790 return -1; 791 } 792 793 // Create SQL statement string 786 794 query = psDBGenerateDeleteRowSQL(tableName, where); 787 795 if (!query) { 788 796 psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed."); 789 790 797 return -1; 791 798 } 792 799 800 // Run SQL query 793 801 if (!p_psDBRunQuery(dbh, query)) { 794 802 psError(PS_ERR_UNKNOWN, false, "Delete failed."); 795 796 803 mysql_rollback(dbh->mysql); 797 798 804 psFree(query); 799 800 805 return -1; 801 806 } 802 803 807 psFree(query); 804 808 805 if (!where) { 806 // we truncated the table so mysql_affected_rows() won't work 807 return 1; 808 } 809 // Get the number of affected row for the delete command 810 rows = (psS64)mysql_affected_rows(dbh->mysql); 809 811 810 812 // point of no return 811 813 mysql_commit(dbh->mysql); 812 814 813 return (psS64)mysql_affected_rows(dbh->mysql);815 return rows; 814 816 } 815 817 … … 1138 1140 if (!where) { 1139 1141 psStringAppend(&query, "TRUNCATE TABLE %s", tableName); 1140 1141 1142 return query; 1142 1143 } 1143 1144 1145 // Generate where SQL substring 1144 1146 whereSQL = psDBGenerateWhereSQL(where); 1145 1147 if (!whereSQL) { 1146 psError(PS_ERR_UNEXPECTED_NULL, false, "SQL substring generation failed.");1147 1148 return NULL;1149 } 1150 1148 psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_SQL_SUBSTR_FAIL); 1149 return NULL; 1150 } 1151 1152 // Complete delete SQL command string 1151 1153 psStringAppend(&query, "DELETE FROM %s %s", tableName, whereSQL); 1152 1154 psFree(whereSQL); … … 1163 1165 if (!where) { 1164 1166 psError(PS_ERR_BAD_PARAMETER_NULL, true, "where param may not be NULL."); 1165 1166 1167 return NULL; 1167 1168 }
Note:
See TracChangeset
for help on using the changeset viewer.
