public static int AddQuery(string name = "", string expr = "") { int pos = 1 + QSqlLite.SqlInt("select max(pos) from tabs where visible<>0 and databaseId=@1", A.dbId); //int result = QSqlLite.Exec("update tabs set pos=pos+1;insert into tabs (name) values ('" + QSqlLite.n(name) + "');"); int result = QSqlLite.Exec("update tabs set pos=pos+1 where databaseId=@1;insert into tabs (name, pos,databaseId) values (@2,@3,@1);", A.dbId, name, pos); if (expr != "") { SaveQuery(result, 0, expr, false); } return(result); }
public static int SaveConnection(string type, string host, string database, string userId, string password, bool savePassword, bool makeDef) { int id = QSqlLite.SqlInt(@"select databaseId from databases where type=@3 and host=@2 and database=@1; ", database, host, type, userId, password); if (id == 0) { id = QSqlLite.Exec(@" insert into databases (databaseId, type, host, database, user, password) values ((select 1 + coalesce(max(databaseId),0) from databases), @3, @2, @1, @4, @5); select databaseId from databases where type=@3 and host=@2 and database=@1; ", database, host, type, userId, password); } else { QSqlLite.Exec("update databases set password=@1 where databaseId=@2", password, id); } initSettings.loadDatabase = makeDef; return(id); }
public static int SaveQuery(int tabId, int currentQueryId, string expr, bool executing) { // string now = "'" + DateTime.Now.ToString("u") + "'"; double now = DateTime.Now.ToEpoch(); expr = QSqlLite.n(expr); bool justUpdate = (currentQueryId != 0 && 0 != QSqlLite.SqlInt("select count(*) from queries where id=" + currentQueryId + " and expr='" + expr + "'")); string sql; if (justUpdate) { sql = "update queries set expr='" + expr + "',when_changed=" + now; sql += " where id = " + currentQueryId; QSqlLite.Exec(sql); } else { sql = "insert into queries (tab_id, expr,when_changed) values (" + tabId + ",'" + expr + "'," + now + ")"; currentQueryId = QSqlLite.Exec(sql); } return(currentQueryId); }