MCPcopy Create free account
hub / github.com/damms005/devdb-vscode / runQuery

Method runQuery

src/database-engines/sqlite-engine.ts:547–587  ·  view source on GitHub ↗
(sql: string, params: any[] = [])

Source from the content-addressed store, hash-verified

545 }
546
547 async runQuery(sql: string, params: any[] = []): Promise<any> {
548 try {
549 const db = this.getConnection();
550 if (!db) {
551 return Promise.reject('Cannot connect to database')
552 }
553
554 return new Promise<any>((resolve, reject) => {
555 // Determine if the query is a SELECT or PRAGMA statement
556 const isSelect = /^\s*(SELECT|PRAGMA)\s+/i.test(sql);
557
558 if (isSelect) {
559 db.all(sql, params, (err, rows) => {
560 if (err) {
561 reportError(`SQLite run query error: ${err}`);
562 reject(err);
563 return;
564 }
565 resolve(rows);
566 });
567 } else {
568 db.run(sql, params, function (err) {
569 if (err) {
570 reportError(`SQLite run query error: ${err}`);
571 reject(err);
572 return;
573 }
574
575 // For non-SELECT queries, return information about the operation
576 resolve({
577 changes: this.changes,
578 lastID: this.lastID
579 });
580 });
581 }
582 });
583 } catch (err) {
584 reportError(`SQLite run query error: ${err}`);
585 throw err;
586 }
587 }
588
589 async close(): Promise<void> {
590 return this.disconnect();

Callers

nothing calls this directly

Calls 2

getConnectionMethod · 0.95
reportErrorFunction · 0.90

Tested by

no test coverage detected