Calling a Variable in an SQLite Select command
Posted: Fri Jul 03, 2020 4:00 am
Hi everyone,
Thanks in advance for your help! A relative newbee here building an app for my senior softball league. I have an SQLite database with 4 tables I want to link with relationships and issue filter statements(plus a few other tables): orgs(organizations), users, events and teams. The first card of the app is a login page. It connects to the database and your access level is based on login info. The 2nd card contains a data grid with a list of organizations. You hilite a line and click on a Select button which stores the org name and ord_id to global mem vars. The name of the org is then inserted on all cards that follow in the headers and the command "go card crdEvents", the 3rd card, is issued. This part works fine.
The Events card contains another data grid with a list of events which are contained in the events table, events for all organizations, separated by the org_id field.
I want to use an SQL select command to populate the data grid, dgEvents, and filter the events by the org_id, stored in the gOrd_id mem var. I tried, among other things:
local tSQL
function getSQL pTable
switch pTable
case "events"
put "SELECT id, orgs_id, year, eventno, eventname, startdate, enddate" && \
"FROM events WHERE orgs_id = gOrg_Id" && \
"ORDER BY eventno ASC" into tSQL
I get the error "Database Error: no such column: gOrg_Id
Then on the next card, crdTeams, I want to populate a data grid with a list from the teams table filter by the org_id and event_id. So I need a 2 condition WHERE clause, something like:
case "teams"
put "SELECT id, orgs_id, events_id, teamname, manager, phone, email" && \
"FROM teams WHERE 'orgs_id' = gOrg_Id AND events_id = gEvents_Id" && \
"ORDER BY teamname ASC" into tSQL
Can someone help with the proper syntax or another approach to this? I'd be most grateful!
Thanks,
Lonnie
Thanks in advance for your help! A relative newbee here building an app for my senior softball league. I have an SQLite database with 4 tables I want to link with relationships and issue filter statements(plus a few other tables): orgs(organizations), users, events and teams. The first card of the app is a login page. It connects to the database and your access level is based on login info. The 2nd card contains a data grid with a list of organizations. You hilite a line and click on a Select button which stores the org name and ord_id to global mem vars. The name of the org is then inserted on all cards that follow in the headers and the command "go card crdEvents", the 3rd card, is issued. This part works fine.
The Events card contains another data grid with a list of events which are contained in the events table, events for all organizations, separated by the org_id field.
I want to use an SQL select command to populate the data grid, dgEvents, and filter the events by the org_id, stored in the gOrd_id mem var. I tried, among other things:
local tSQL
function getSQL pTable
switch pTable
case "events"
put "SELECT id, orgs_id, year, eventno, eventname, startdate, enddate" && \
"FROM events WHERE orgs_id = gOrg_Id" && \
"ORDER BY eventno ASC" into tSQL
I get the error "Database Error: no such column: gOrg_Id
Then on the next card, crdTeams, I want to populate a data grid with a list from the teams table filter by the org_id and event_id. So I need a 2 condition WHERE clause, something like:
case "teams"
put "SELECT id, orgs_id, events_id, teamname, manager, phone, email" && \
"FROM teams WHERE 'orgs_id' = gOrg_Id AND events_id = gEvents_Id" && \
"ORDER BY teamname ASC" into tSQL
Can someone help with the proper syntax or another approach to this? I'd be most grateful!
Thanks,
Lonnie