Changeset 4382 for trunk/psLib/src/db
- Timestamp:
- Jun 24, 2005, 11:29:41 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/db/psDB.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/db/psDB.c
r4373 r4382 12 12 * @author Joshua Hoblitt 13 13 * 14 * @version $Revision: 1.3 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-06-24 02:09:23$14 * @version $Revision: 1.33 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-06-24 21:29:41 $ 16 16 * 17 17 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 708 708 my_ulonglong rowsAffected; // number of rows affected by query 709 709 710 // Verify database object is not NULL 711 if(dbh == NULL) { 712 psError(PS_ERR_UNEXPECTED_NULL,true,PS_ERRORTEXT_psDB_INVALID_PSDB); 713 return -1; 714 } 715 716 // Generate SQL query to update row 710 717 query = psDBGenerateUpdateRowSQL(tableName, where, values); 711 718 if (!query) { 712 psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed."); 713 719 psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_QUERY_GEN_FAIL); 714 720 return -1; 715 721 } 716 722 723 // Initialize SQL statement 717 724 stmt = mysql_stmt_init(dbh->mysql); 718 725 if (!stmt) { … … 720 727 } 721 728 729 // Prepare SQL statement 722 730 if (mysql_stmt_prepare(stmt, query, (unsigned long)strlen(query))) { 723 psError(PS_ERR_UNKNOWN, true, "Failed to prepare query. Error: %s", mysql_stmt_error(stmt)); 724 731 psError(PS_ERR_UNKNOWN, true, PS_ERRORTEXT_psDB_SQL_PREPARE_FAIL, mysql_stmt_error(stmt)); 725 732 mysql_stmt_close(stmt); 726 733 psFree(query); 727 728 734 return -1; 729 735 } 730 731 736 psFree(query); 732 737 … … 743 748 psFree(bind); 744 749 mysql_stmt_close(stmt); 745 746 750 return -1; 747 751 } … … 749 753 if (mysql_stmt_bind_param(stmt, bind)) { 750 754 psError(PS_ERR_UNKNOWN, true, "Failed to bind params. Error: %s", mysql_stmt_error(stmt)); 751 752 755 mysql_rollback(dbh->mysql); 753 754 756 psFree(bind); 755 757 mysql_stmt_close(stmt); 756 757 758 return -1; 758 759 } … … 761 762 psError(PS_ERR_UNKNOWN, true, "Failed to execute prepared statement. Error: %s", 762 763 mysql_stmt_error(stmt)); 763 764 764 mysql_rollback(dbh->mysql); 765 766 765 psFree(bind); 767 766 mysql_stmt_close(stmt); 768 769 767 return -1; 770 768 } … … 845 843 psU32 i; // field index 846 844 845 // Verify values or bind are not null 846 if((values == NULL) || (bind == NULL)) { 847 return false; 848 } 849 847 850 // check size of values == paramCount ? 848 849 851 cursor = psListIteratorAlloc(values->list, 0, false); 850 852 … … 1100 1102 char *whereSQL; 1101 1103 1104 // Verify where and values pointer are not NULL 1102 1105 if ((!values) || (!where)) { 1103 psError(PS_ERR_BAD_PARAMETER_NULL, true, "values and where params may not be NULL.");1104 1105 return NULL;1106 } 1107 1106 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psDB_UPDATE_ROW_FAIL); 1107 return NULL; 1108 } 1109 1110 // Create set SQL substring 1108 1111 setSQL = psDBGenerateSetSQL(values); 1109 1112 if (!setSQL) { 1110 psError(PS_ERR_UNEXPECTED_NULL, false, "SQL substring generation failed.");1111 1112 return NULL;1113 } 1114 1113 psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_SQL_SUBSTR_FAIL); 1114 return NULL; 1115 } 1116 1117 // Create where SQL substring 1115 1118 whereSQL = psDBGenerateWhereSQL(where); 1116 1119 if (!whereSQL) { 1117 psError(PS_ERR_UNEXPECTED_NULL, false, "SQL substring generation failed.");1118 1119 return NULL;1120 } 1121 1120 psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_SQL_SUBSTR_FAIL); 1121 return NULL; 1122 } 1123 1124 // Append substring to SQL update string 1122 1125 psStringAppend(&query, "UPDATE %s %s %s", tableName, setSQL, whereSQL); 1123 1126 psFree(setSQL);
Note:
See TracChangeset
for help on using the changeset viewer.
