* insert -- given the data row (v) and its length (vlen), we build the corresponding * key, and insert the data in to the db. * This will over-right the value if already present. */
| 571 | * This will over-right the value if already present. |
| 572 | */ |
| 573 | int insert(table_p tp, char* v, int vlen) |
| 574 | { |
| 575 | char k[MAX_ROW_SIZE]; |
| 576 | int rc, klen; |
| 577 | DB *db; |
| 578 | |
| 579 | if(!tp || !v) return 1; |
| 580 | if((db = get_db(tp)) == NULL) return 2; |
| 581 | |
| 582 | memset(k,0,MAX_ROW_SIZE); |
| 583 | if( extract_key(tp, k, v) ) |
| 584 | { |
| 585 | fprintf(stderr, "[insert] failed to extract key for row: %.*s",vlen, v); |
| 586 | return 2; |
| 587 | } |
| 588 | |
| 589 | klen = strlen(k); |
| 590 | rc = _insert(db, k, v, klen, vlen); |
| 591 | |
| 592 | return rc; |
| 593 | } |
| 594 | |
| 595 | |
| 596 | /** |