Changeset 4389 for trunk/psLib/src/db/psDB.c
- Timestamp:
- Jun 24, 2005, 3:16:50 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/db/psDB.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
