( statement: string, connectorType: ConnectorType )
| 55 | * @throws Error if parameter style doesn't match connector |
| 56 | */ |
| 57 | export function validateParameterStyle( |
| 58 | statement: string, |
| 59 | connectorType: ConnectorType |
| 60 | ): void { |
| 61 | const detectedStyle = detectParameterStyle(statement); |
| 62 | const expectedStyle = PARAMETER_STYLES[connectorType]; |
| 63 | |
| 64 | if (detectedStyle === "none") { |
| 65 | // No parameters in statement - this is valid |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | if (detectedStyle !== expectedStyle) { |
| 70 | const examples = { |
| 71 | numbered: "$1, $2, $3", |
| 72 | positional: "?, ?, ?", |
| 73 | named: "@p1, @p2, @p3", |
| 74 | }; |
| 75 | |
| 76 | throw new Error( |
| 77 | `Invalid parameter syntax for ${connectorType}. ` + |
| 78 | `Expected ${expectedStyle} style (${examples[expectedStyle]}), ` + |
| 79 | `but found ${detectedStyle} style in statement.` |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Count the number of parameters in a SQL statement and validate they are sequential. |
no test coverage detected