| 113 | } |
| 114 | |
| 115 | fn parse_set_idle_timeout(parts: &[&str]) -> Result<AlterDatabaseOperation, SqlError> { |
| 116 | let eq = parts.get(5).copied().unwrap_or(""); |
| 117 | if eq != "=" { |
| 118 | return Err(SqlError::Parse { |
| 119 | detail: format!("ALTER DATABASE SET IDLE_TIMEOUT requires '=', got '{eq}'"), |
| 120 | }); |
| 121 | } |
| 122 | let raw = parts.get(6).copied().ok_or_else(|| SqlError::Parse { |
| 123 | detail: "ALTER DATABASE SET IDLE_TIMEOUT requires a non-negative integer (seconds)".into(), |
| 124 | })?; |
| 125 | let secs = raw |
| 126 | .trim_matches('\'') |
| 127 | .trim_matches('"') |
| 128 | .parse::<u64>() |
| 129 | .map_err(|_| SqlError::Parse { |
| 130 | detail: format!( |
| 131 | "ALTER DATABASE SET IDLE_TIMEOUT: invalid value '{raw}', expected non-negative integer" |
| 132 | ), |
| 133 | })?; |
| 134 | if secs > MAX_IDLE_TIMEOUT_SECS { |
| 135 | return Err(SqlError::Parse { |
| 136 | detail: format!( |
| 137 | "ALTER DATABASE SET IDLE_TIMEOUT: {secs}s exceeds maximum {MAX_IDLE_TIMEOUT_SECS}s ({} days). \ |
| 138 | Use 0 to disable the timeout entirely.", |
| 139 | MAX_IDLE_TIMEOUT_SECS / 86_400 |
| 140 | ), |
| 141 | }); |
| 142 | } |
| 143 | Ok(AlterDatabaseOperation::SetIdleTimeout(secs)) |
| 144 | } |
| 145 | |
| 146 | #[cfg(test)] |
| 147 | mod tests { |