Changeset 3196
- Timestamp:
- Feb 11, 2005, 1:19:25 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/psdb/psDB.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/psdb/psDB.c
r3195 r3196 8 8 * @author Joshua Hoblitt 9 9 * 10 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-02-11 2 1:52:33$10 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-02-11 23:19:25 $ 12 12 * 13 13 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 54 54 // database utility functions 55 55 static bool psDBRunQuery(psDB *dbh, const char *query); 56 static inline bool psDBPackRow(MYSQL_BIND *bind, psMetadata *values, psU32 paramCount); 56 57 57 58 // SQL generation functions … … 407 408 md = psMetadataAlloc(); 408 409 409 fieldLength = (psU64 *) (mysql_fetch_lengths(result));410 fieldLength = (psU64 *)mysql_fetch_lengths(result); 410 411 411 412 for (i = 0; i < fieldCount; i++) { … … 636 637 i = 0; 637 638 while ((item = psListGetNext(cursor))) { 639 // lookup pType -> mysql type 638 640 key = psDBIntToString((psU64)item->pType); 639 641 mType = psHashLookup(mysqlFieldType, key); … … 752 754 paramCount = (psU32)mysql_stmt_param_count(stmt); 753 755 754 // structure large renough to hold one field of data per place holder756 // structure large enough to hold one field of data per place holder 755 757 bind = psAlloc(sizeof(MYSQL_BIND) * paramCount); 758 759 // init bind 760 memset(bind, 0, sizeof(MYSQL_BIND) * paramCount); 761 762 if (!psDBPackRow(bind, values, paramCount)) { 763 psFree(bind); 764 mysql_stmt_close(stmt); 765 766 return -1; 767 } 756 768 757 769 if (mysql_stmt_bind_param(stmt, bind)) { … … 787 799 788 800 return rowsAffected; 801 } 802 803 static inline bool psDBPackRow(MYSQL_BIND *bind, psMetadata *values, psU32 paramCount) 804 { 805 psListIterator *cursor; // row iterator 806 psMetadataItem *item; // field in row 807 psHash *mysqlFieldType; // type lookup table 808 mysqlType *mType; // type tmp variable 809 bool isNull = true; // used in a MYSQL_BIND to indicate NULL 810 char *key; // hash tmp variable 811 int i; 812 813 // check size of values == paramCount ? 814 815 cursor = psListIteratorAlloc(values->list, 0); 816 817 mysqlFieldType = psDBGetPSToMySQLTable(); 818 819 // loop over fields 820 i = 0; 821 while ((item = psListGetNext(cursor))) { 822 // lookup pType -> mysql type 823 key = psDBIntToString((psU64)item->pType); 824 mType = psHashLookup(mysqlFieldType, key); 825 psFree(key); 826 827 // input data length is determined by the MYSQL_TYPE_* unless it's a string 828 bind[i].buffer = (char *)item->data.V; 829 bind[i].buffer_type = mType->type; 830 bind[i].is_unsigned = mType->isUnsigned; 831 832 // convert NaNs to NULL 833 bind[i].is_null = psDBIsPTypeNaN(item->pType, item->data.V) 834 ? (my_bool *)&isNull 835 : NULL; 836 837 if (item->pType == PS_TYPE_PTR) { 838 if (item->type == PS_META_STR) { 839 if (*(char *)item->data.V == '\0') { 840 bind[i].is_null = (my_bool *)&isNull; 841 } else { 842 bind[i].buffer_length = (unsigned long)strlen((char *)item->data.V); 843 bind[i].is_null = NULL; 844 } 845 } else { 846 // error, not a pointer to a string 847 psFree(cursor); 848 849 return false; 850 } 851 } 852 853 // increment field index 854 i++; 855 } 856 857 psFree(cursor); 858 psFree(mysqlFieldType); 859 860 return true; 789 861 } 790 862
Note:
See TracChangeset
for help on using the changeset viewer.
