MCPcopy Create free account
hub / github.com/bytebase/dbhub / validateParameterStyle

Function validateParameterStyle

src/utils/parameter-mapper.ts:57–82  ·  view source on GitHub ↗
(
  statement: string,
  connectorType: ConnectorType
)

Source from the content-addressed store, hash-verified

55 * @throws Error if parameter style doesn't match connector
56 */
57export 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.

Callers 2

validateParametersFunction · 0.85

Calls 1

detectParameterStyleFunction · 0.85

Tested by

no test coverage detected