Changeset 3197
- Timestamp:
- Feb 11, 2005, 1:35:23 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/psdb/psDB.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/psdb/psDB.c
r3196 r3197 8 8 * @author Joshua Hoblitt 9 9 * 10 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-02-11 23: 19:25$10 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-02-11 23:35:23 $ 12 12 * 13 13 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 581 581 MYSQL_BIND *bind; // field values to insert 582 582 psU32 paramCount; // number of placeholders in query 583 psHash *mysqlFieldType; // type lookup table584 mysqlType *mType; // type tmp variable585 char *key; // hash tmp variable586 psMetadataItem *item; // field in row587 psListIterator *cursor; // row iterator588 psU32 i; // field index589 583 psU64 j; // row index 590 bool isNull = true; // used in a MYSQL_BIND to indicate NULL591 584 592 585 // we are assuming that all rows in the set have an identical with reguard … … 624 617 bind = psAlloc(sizeof(MYSQL_BIND) * paramCount); 625 618 626 mysqlFieldType = psDBGetPSToMySQLTable();627 628 619 // loop over rows 629 620 for (j = 0; j < rowSet->n; j++) { 630 // extract the psList, from the psMetadata, in the current psArray element 631 cursor = psListIteratorAlloc(((psMetadata *)rowSet->data[j])->list, 0); 621 row = rowSet->data[j]; 632 622 633 623 // reset bind for each row 634 624 memset(bind, 0, sizeof(MYSQL_BIND) * paramCount); 635 625 636 // loop over fields 637 i = 0; 638 while ((item = psListGetNext(cursor))) { 639 // lookup pType -> mysql type 640 key = psDBIntToString((psU64)item->pType); 641 mType = psHashLookup(mysqlFieldType, key); 642 psFree(key); 643 644 // input data length is determined by the MYSQL_TYPE_* unless it's a string 645 bind[i].buffer = (char *)item->data.V; 646 bind[i].buffer_type = mType->type; 647 bind[i].is_unsigned = mType->isUnsigned; 648 649 // convert NaNs to NULL 650 bind[i].is_null = psDBIsPTypeNaN(item->pType, item->data.V) 651 ? (my_bool *)&isNull 652 : NULL; 653 654 if (item->pType == PS_TYPE_PTR) { 655 if (item->type == PS_META_STR) { 656 if (*(char *)item->data.V == '\0') { 657 bind[i].is_null = (my_bool *)&isNull; 658 } else { 659 bind[i].buffer_length = (unsigned long)strlen((char *)item->data.V); 660 bind[i].is_null = NULL; 661 } 662 } else { 663 // error, not a pointer to a string 664 mysql_rollback(dbh->mysql); 665 666 psFree(cursor); 667 psFree(bind); 668 mysql_stmt_close(stmt); 669 670 return false; 671 } 672 } 673 674 // increment field index 675 i++; 676 } 677 678 psFree(cursor); 626 if (!psDBPackRow(bind, row, paramCount)) { 627 fprintf(stderr, "Failed to pack params into bind structure.\n"); 628 629 mysql_rollback(dbh->mysql); 630 631 psFree(bind); 632 mysql_stmt_close(stmt); 633 } 679 634 680 635 if (mysql_stmt_bind_param(stmt, bind)) { … … 700 655 } 701 656 } // end loop over rows 702 703 psFree(mysqlFieldType);704 657 705 658 // point of no return … … 807 760 psHash *mysqlFieldType; // type lookup table 808 761 mysqlType *mType; // type tmp variable 809 bool isNull = true; // used in a MYSQL_BIND to indicate NULL 762 static bool isNull = true; // used in a MYSQL_BIND to indicate NULL, 763 // this will be used outside of this func 810 764 char *key; // hash tmp variable 811 int i;765 psU32 i; // field index 812 766 813 767 // check size of values == paramCount ? … … 846 800 // error, not a pointer to a string 847 801 psFree(cursor); 802 psFree(mysqlFieldType); 848 803 849 804 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
