deleted: backend/check_endpoints.js

modified:   backend/src/services/SqlExecutor.ts
This commit is contained in:
GEgorov
2025-11-29 16:37:31 +03:00
parent 675d455d23
commit 0cca6f5d8e
2 changed files with 2 additions and 72 deletions

View File

@@ -1,49 +0,0 @@
const { Client } = require('pg');
async function testQueries() {
// Подключаемся к целевой БД (emias_pg)
const client = new Client({
host: 'm112-pgkisc-01.ncms-i.ru',
port: 5432,
database: 'kis',
user: 'XАПИД',
password: 'c4d504412b61b0560d442686dfad27'
});
await client.connect();
console.log('Connected to kis database');
const caseId = 'f580b03b-86ee-41b6-a697-1981f116c669';
// Запрос из проблемного эндпоинта (с табами)
const queryWithTabs = `SELECT\tea.c_uid a_uid,
\tp.ehr_id ehrid,
\tp.erz_number subjectid,
\tp.namespace namespace
FROM \tmm.ehr_case ec
\tINNER JOIN mm.ehr_case_action ea ON ec.last_action_id = ea.id
\tINNER JOIN mm.hospdoc hd ON hd.ehr_case_id = ec.id
\tINNER JOIN mm.mdoc md ON md.id = hd.mdoc_id
\tINNER JOIN mm.people p ON p.id = md.people_id
WHERE\tec.id = $1
AND\thd.location_status_id = 1`;
// Запрос из рабочего эндпоинта (с пробелами и CRLF)
const queryWithSpaces = `SELECT ea.c_uid a_uid,\r\n p.ehr_id ehrid,\r\n p.erz_number subjectid,\r\n p.namespace namespace\r\n FROM mm.ehr_case ec\r\n INNER JOIN mm.ehr_case_action ea ON ec.last_action_id = ea.id\r\n INNER JOIN mm.hospdoc hd ON hd.ehr_case_id = ec.id\r\n INNER JOIN mm.mdoc md ON md.id = hd.mdoc_id\r\n INNER JOIN mm.people p ON p.id = md.people_id\r\n WHERE ec.id = $1\r\n AND hd.location_status_id = 1`;
console.log('\n=== Query with TABS (problematic) ===');
console.log('HEX first 50:', Buffer.from(queryWithTabs.substring(0, 50)).toString('hex'));
const result1 = await client.query(queryWithTabs, [caseId]);
console.log('rowCount:', result1.rowCount);
console.log('rows:', JSON.stringify(result1.rows));
console.log('\n=== Query with SPACES (working) ===');
console.log('HEX first 50:', Buffer.from(queryWithSpaces.substring(0, 50)).toString('hex'));
const result2 = await client.query(queryWithSpaces, [caseId]);
console.log('rowCount:', result2.rowCount);
console.log('rows:', JSON.stringify(result2.rows));
await client.end();
}
testQueries().catch(console.error);

View File

@@ -47,33 +47,12 @@ export class SqlExecutor {
this.validateQuery(sqlQuery);
// Log SQL query and parameters before execution
console.log('\n[SQL DB]', databaseId);
// @ts-ignore - accessing pool options for debugging
const poolOpts = pool.options;
console.log('[SQL Pool Config] host:', poolOpts?.host, 'database:', poolOpts?.database, 'user:', poolOpts?.user);
console.log('[SQL Query]', sqlQuery);
console.log('\n[SQL Query]', sqlQuery);
console.log('[SQL Params]', params);
// Execute with retry mechanism
const result = await this.retryQuery(async () => {
// Check if connected to replica
const debugResult = await pool.query(`
SELECT
pg_backend_pid() as pid,
pg_is_in_recovery() as is_replica,
inet_server_addr() as server_ip
`);
const d = debugResult.rows[0];
console.log('[SQL Debug] pid:', d?.pid, 'is_replica:', d?.is_replica, 'server_ip:', d?.server_ip);
// Disable prepared statements by using unique name each time
const queryResult = await pool.query({
text: sqlQuery,
values: params,
name: undefined // This disables prepared statement caching
});
console.log('[SQL Result] rowCount:', queryResult.rowCount, 'rows:', JSON.stringify(queryResult.rows).substring(0, 500));
return queryResult;
return await pool.query(sqlQuery, params);
}, 3, 500); // 3 попытки с задержкой 500ms
const executionTime = Date.now() - startTime;