array_length(array, dimension) - Get length of array in specified dimension
(conn: &Connection)
| 40 | |
| 41 | /// array_length(array, dimension) - Get length of array in specified dimension |
| 42 | fn register_array_length(conn: &Connection) -> Result<()> { |
| 43 | conn.create_scalar_function( |
| 44 | "array_length", |
| 45 | 2, |
| 46 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 47 | |ctx| { |
| 48 | let array_json: String = ctx.get(0)?; |
| 49 | let dimension: i32 = ctx.get(1)?; |
| 50 | |
| 51 | match serde_json::from_str::<JsonValue>(&array_json) { |
| 52 | Ok(JsonValue::Array(arr)) => { |
| 53 | if dimension == 1 { |
| 54 | Ok(Some(arr.len() as i32)) |
| 55 | } else { |
| 56 | // For higher dimensions, check first element |
| 57 | if let Some(JsonValue::Array(inner)) = arr.first() { |
| 58 | if dimension == 2 { |
| 59 | Ok(Some(inner.len() as i32)) |
| 60 | } else { |
| 61 | Ok(None) // Higher dimensions not yet supported |
| 62 | } |
| 63 | } else { |
| 64 | Ok(None) |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | _ => Ok(None), |
| 69 | } |
| 70 | }, |
| 71 | )?; |
| 72 | |
| 73 | Ok(()) |
| 74 | } |
| 75 | |
| 76 | /// array_upper(array, dimension) - Get upper bound of array dimension |
| 77 | fn register_array_upper(conn: &Connection) -> Result<()> { |
no test coverage detected