* Insert a row into table */
| 647 | * Insert a row into table |
| 648 | */ |
| 649 | int bdb_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n) |
| 650 | { |
| 651 | tbl_cache_p _tbc = NULL; |
| 652 | table_p _tp = NULL; |
| 653 | char kbuf[MAX_ROW_SIZE]; |
| 654 | char dbuf[MAX_ROW_SIZE]; |
| 655 | int i, j, ret, klen, dlen; |
| 656 | int *lkey=NULL; |
| 657 | DBT key, data; |
| 658 | DB *db; |
| 659 | |
| 660 | i = j = ret = 0; |
| 661 | klen=MAX_ROW_SIZE; |
| 662 | dlen=MAX_ROW_SIZE; |
| 663 | |
| 664 | if ((!_h) || (!_v) || !CON_TABLE(_h)) |
| 665 | { return -1; |
| 666 | } |
| 667 | |
| 668 | if (!_k) |
| 669 | { |
| 670 | #ifdef BDB_EXTRA_DEBUG |
| 671 | LM_ERR("DB INSERT without KEYs not implemented! \n"); |
| 672 | #endif |
| 673 | return -2; |
| 674 | } |
| 675 | |
| 676 | _tbc = bdblib_get_table(BDB_CON_CONNECTION(_h), (str*)CON_TABLE(_h)); |
| 677 | if(!_tbc) |
| 678 | { LM_WARN("table does not exist!\n"); |
| 679 | return -3; |
| 680 | } |
| 681 | |
| 682 | _tp = _tbc->dtp; |
| 683 | if(!_tp) |
| 684 | { LM_WARN("table not loaded!\n"); |
| 685 | return -4; |
| 686 | } |
| 687 | |
| 688 | #ifdef BDB_EXTRA_DEBUG |
| 689 | LM_DBG("INSERT in %.*s\n", _tp->name.len, _tp->name.s ); |
| 690 | #endif |
| 691 | |
| 692 | db = _tp->db; |
| 693 | memset(&key, 0, sizeof(DBT)); |
| 694 | memset(kbuf, 0, klen); |
| 695 | |
| 696 | if(_tp->ncols<_n) |
| 697 | { LM_WARN("more values than columns!!\n"); |
| 698 | return -5; |
| 699 | } |
| 700 | |
| 701 | lkey = bdb_get_colmap(_tp, _k, _n); |
| 702 | if(!lkey) return -7; |
| 703 | |
| 704 | /* verify col types provided */ |
| 705 | for(i=0; i<_n; i++) |
| 706 | { j = lkey[i]; |
nothing calls this directly
no test coverage detected