array_lower(array, dimension) - Get lower bound (always 1 for PostgreSQL arrays)
(conn: &Connection)
| 108 | |
| 109 | /// array_lower(array, dimension) - Get lower bound (always 1 for PostgreSQL arrays) |
| 110 | fn register_array_lower(conn: &Connection) -> Result<()> { |
| 111 | conn.create_scalar_function( |
| 112 | "array_lower", |
| 113 | 2, |
| 114 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 115 | |ctx| { |
| 116 | let array_json: String = ctx.get(0)?; |
| 117 | let dimension: i32 = ctx.get(1)?; |
| 118 | |
| 119 | match serde_json::from_str::<JsonValue>(&array_json) { |
| 120 | Ok(JsonValue::Array(arr)) => { |
| 121 | if arr.is_empty() { |
| 122 | Ok(None) |
| 123 | } else if dimension == 1 { |
| 124 | Ok(Some(1)) |
| 125 | } else if dimension == 2 { |
| 126 | // Check if it's actually a 2D array |
| 127 | if let Some(JsonValue::Array(_)) = arr.first() { |
| 128 | Ok(Some(1)) |
| 129 | } else { |
| 130 | Ok(None) |
| 131 | } |
| 132 | } else { |
| 133 | Ok(None) |
| 134 | } |
| 135 | } |
| 136 | _ => Ok(None), |
| 137 | } |
| 138 | }, |
| 139 | )?; |
| 140 | |
| 141 | Ok(()) |
| 142 | } |
| 143 | |
| 144 | /// array_ndims(array) - Get number of dimensions |
| 145 | fn register_array_ndims(conn: &Connection) -> Result<()> { |
no test coverage detected