modified: backend/check_endpoints.js
modified: backend/src/services/SqlExecutor.ts
This commit is contained in:
@@ -1,33 +1,49 @@
|
|||||||
const { Client } = require('pg');
|
const { Client } = require('pg');
|
||||||
|
|
||||||
async function checkEndpoints() {
|
async function testQueries() {
|
||||||
|
// Подключаемся к целевой БД (emias_pg)
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
host: '192.168.0.150',
|
host: 'm112-pgkisc-01.ncms-i.ru',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
database: 'kis_api_builder_db',
|
database: 'kis',
|
||||||
user: 'kis_api_builder',
|
user: 'XАПИД',
|
||||||
password: 'kis_api_builder_pass'
|
password: 'c4d504412b61b0560d442686dfad27'
|
||||||
});
|
});
|
||||||
|
|
||||||
await client.connect();
|
await client.connect();
|
||||||
|
console.log('Connected to kis database');
|
||||||
|
|
||||||
const query = `
|
const caseId = 'f580b03b-86ee-41b6-a697-1981f116c669';
|
||||||
SELECT
|
|
||||||
e.path,
|
|
||||||
e.script_queries::text as script_queries
|
|
||||||
FROM endpoints e
|
|
||||||
WHERE e.path IN ('/hosp/updateHospData', '/apitesttest')
|
|
||||||
`;
|
|
||||||
|
|
||||||
const result = await client.query(query);
|
// Запрос из проблемного эндпоинта (с табами)
|
||||||
|
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`;
|
||||||
|
|
||||||
for (const row of result.rows) {
|
// Запрос из рабочего эндпоинта (с пробелами и CRLF)
|
||||||
console.log('\n========================================');
|
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('PATH:', row.path);
|
|
||||||
console.log('SCRIPT_QUERIES:', row.script_queries);
|
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();
|
await client.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEndpoints().catch(console.error);
|
testQueries().catch(console.error);
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ export class SqlExecutor {
|
|||||||
|
|
||||||
// Log SQL query and parameters before execution
|
// Log SQL query and parameters before execution
|
||||||
console.log('\n[SQL DB]', databaseId);
|
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('[SQL Query]', sqlQuery);
|
||||||
console.log('[SQL Query HEX first 100 chars]', Buffer.from(sqlQuery.substring(0, 100)).toString('hex'));
|
|
||||||
console.log('[SQL Params]', params);
|
console.log('[SQL Params]', params);
|
||||||
|
|
||||||
// Execute with retry mechanism
|
// Execute with retry mechanism
|
||||||
|
|||||||
Reference in New Issue
Block a user