SELECT with an ALIAS
Posted: Thu Oct 31, 2013 9:14 pm
The below code doesn't work because I can't find any way to assign an alias to the workarea after a SELECT statment. The alias always comes back as QUERY.
The docs claim that I should be able to use the AS <cAliasName> but it will not work no matter how I try. Has anyone done this?
See the below code:
The docs claim that I should be able to use the AS <cAliasName> but it will not work no matter how I try. Has anyone done this?
See the below code:
Code: Select all
#include "pgdbe.ch"
#include "dcdialog.CH"
#Pragma Library("dclipx.lib")
#Pragma Library("dclip1.lib")
FUNCTION Main
LOCAL oSession, cConnStr, GetList[0], oBrowse, cFieldName, i, aStru
DbeLoad("pgdbe")
DbeSetDefault("pgdbe")
cConnStr := "DBE=pgdbe;server=localhost;"
cConnStr += "db=Topline;uid=postgres;pwd=postgres"
oSession := DacSession():New(cConnStr)
IF(!oSession:IsConnected())
MsgBox("Connection failed ("+Var2Char(oSession:GetLastMessage())+")")
QUIT
ENDIF
/* We can not use File() to verify if a table exists. Use Table()
* instead. Table() works with dbf tables, sql tables, local or
* remote.
*/
BEGIN SEQUENCE
MsgBox("Connected to PostgreSQL server")
IF !Table("Parts")
MsgBox("No PARTS table")
BREAK
ENDIF
SELECT * FROM PARTS
aStru := PARTS->(dbStruct())
@ 0,0 DCBROWSE oBrowse ALIAS 'PARTS' SIZE 100,20
FOR i := 1 TO Len(aStru)
cFieldName := aStru[i,1]
DCBROWSECOL DATA DC_FieldWBlock(cFieldName,'PARTS') ;
HEADER cFieldName WIDTH 10 PARENT oBrowse
NEXT
DCREAD GUI FIT TITLE 'Browsing PARTS using PostGreSql'
END SEQUENCE
oSession:Disconnect()
RETURN nil
* --------------
PROC appsys ; RETURN