Parse the provided [`tiberius::Row`] to determine what [`Operation`] occurred. See .
(data: tiberius::Row)
| 732 | /// |
| 733 | /// See <https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/cdc-fn-cdc-get-all-changes-capture-instance-transact-sql?view=sql-server-ver16#table-returned>. |
| 734 | fn try_parse(data: tiberius::Row) -> Result<(Lsn, Self), SqlServerError> { |
| 735 | static START_LSN_COLUMN: &str = "__$start_lsn"; |
| 736 | static OPERATION_COLUMN: &str = "__$operation"; |
| 737 | static SEQVAL_COLUMN: &str = "__$seqval"; |
| 738 | |
| 739 | let lsn: &[u8] = data |
| 740 | .try_get(START_LSN_COLUMN) |
| 741 | .map_err(|e| CdcError::RequiredColumn { |
| 742 | column_name: START_LSN_COLUMN, |
| 743 | error: e.to_string(), |
| 744 | })? |
| 745 | .ok_or_else(|| CdcError::RequiredColumn { |
| 746 | column_name: START_LSN_COLUMN, |
| 747 | error: "got null value".to_string(), |
| 748 | })?; |
| 749 | let operation: i32 = data |
| 750 | .try_get(OPERATION_COLUMN) |
| 751 | .map_err(|e| CdcError::RequiredColumn { |
| 752 | column_name: OPERATION_COLUMN, |
| 753 | error: e.to_string(), |
| 754 | })? |
| 755 | .ok_or_else(|| CdcError::RequiredColumn { |
| 756 | column_name: OPERATION_COLUMN, |
| 757 | error: "got null value".to_string(), |
| 758 | })?; |
| 759 | let seqval: &[u8] = data |
| 760 | .try_get(SEQVAL_COLUMN) |
| 761 | .map_err(|e| CdcError::RequiredColumn { |
| 762 | column_name: SEQVAL_COLUMN, |
| 763 | error: e.to_string(), |
| 764 | })? |
| 765 | .ok_or_else(|| CdcError::RequiredColumn { |
| 766 | column_name: SEQVAL_COLUMN, |
| 767 | error: "got null value".to_string(), |
| 768 | })?; |
| 769 | |
| 770 | let lsn = Lsn::try_from(lsn).map_err(|msg| SqlServerError::InvalidData { |
| 771 | column_name: START_LSN_COLUMN.to_string(), |
| 772 | error: msg, |
| 773 | })?; |
| 774 | let seqval = Lsn::try_from(seqval).map_err(|msg| SqlServerError::InvalidData { |
| 775 | column_name: SEQVAL_COLUMN.to_string(), |
| 776 | error: msg, |
| 777 | })?; |
| 778 | |
| 779 | let operation = match operation { |
| 780 | 1 => Operation::Delete(data), |
| 781 | 2 => Operation::Insert(data), |
| 782 | 3 => Operation::UpdateOld(seqval, data), |
| 783 | 4 => Operation::UpdateNew(seqval, data), |
| 784 | other => { |
| 785 | return Err(SqlServerError::InvalidData { |
| 786 | column_name: OPERATION_COLUMN.to_string(), |
| 787 | error: format!("unrecognized operation {other}"), |
| 788 | }); |
| 789 | } |
| 790 | }; |
| 791 |