At new at Clarion and i’m trying to do an integration with the PostgreSQL, but i’m having a lot of problems.
Is there any place where I can find a tutorial to follow to learn how to use SQL sentences in Clarion? It doesn’t has to be something very complex, I just want to know how to execute the basics like “insert”, “select”, “update” and this kind of stuff and how to deal with them using Clarion.
would be great to me, because I have a lot of douts about it.
The best approach sometimes depends on what you are trying to do though. Perhaps if you have a specific question to use as a starting point?
I had a quick look in the examples that come with Clarion but I see nothing specific to PostgreSQL and I have no familiarity with that myself so I can’t help you there.
Are you aware of the roles of Database Drivers in Clarion and using Clarion Views? Below are some quotes from the help
Database Drivers “Clarion achieves database independence with its built-in driver technology, which lets you access data from virtually any file system using the same set of Clarion language commands. Many file drivers are available and more are being added”
VIEW Declares a “virtual” file as a composite of related files.
Hopefully someone else with PostgreSQL experience will chip in here too at some point!
Another thing to try is trace logging. See the section Logging Driver I/O for debugging in the help file.
In particular:
On Demand Logging
For on-demand logging you can use property syntax within your program to conditionally turn various levels of logging on and off. The logging is effective for the target table and any view for which the target table is the primary table.
file{PROP:Profile}=Pathname !Turns Clarion I/O logging on
file{PROP:Profile}='' !Turns Clarion I/O logging off
PathName = file{PROP:Profile} !Queries the name of the log file
file{PROP:Log}=string !Writes the string to the log file
file{PROP:Details}=1 !Turns Record Buffer logging on
fFile{PROP:Details}=0 !Turns Record Buffer logging off
I created a QUEUE with only one column and i’m trying to execute a “select” that should return a value which is equals to the type of the field in the QUEUE. The SQL runs with no problem, but I have no return.
Thats the code: QSQL:CodCliente{PROP:SQL} = ‘select cltcodigo from tblclientes where cltcodigo like ‘’’ & CAD:Codigo & ‘’’’
If I message the “QSQL:CodCliente”, it returns an empty value. It’s not a SQL error, because if I try to execute the same SQL with the same value in the end of it at the BD I have normal return.
PROP:SQL will only work with a FILE. So to get your data into a QUEUE you would need to do something like this:
MyFile{PROP:SQL} = 'select cltcodigo from tblclientes where cltcodigo like ''' & CAD:Codigo & '''
LOOP
Next(MyFile)
IF ErrorCode()
BREAK
END
QSQL:CodCliente.SomeField = MyFile.SomeField
Add(QSQL:CodCliente)
END
tblclientes{PROP:SQL} = 'select cltcodigo from tblclientes where cltcodigo like ' & CAD:Codigo & '''
message(WLECLI:cltcodigo) <<<<<<<<<<<<<< THIS MESSAGE RETURNS EMPTY
loop
next(tblclientes)
if errorcode()
if clip(CAD:FisicaJuridica) = 'J'
do some magic over here
if error()
do some magic over here
end
else
do some magic here
if error()
do some magic here too
end
end
end
break
end
Can you see the problem? The message in the beginning of the code return an empty string.
The PROP:SQL executes the SQL statement against the server, it is not until you issue the Next(tblclientes) that values are moved to the table record buffer. Also, don’t forget to check for errors e.g.
tblclientes{PROP:SQL} = 'select cltcodigo from tblclientes where cltcodigo like ' & CAD:Codigo & '''
IF ErrorCode()
Message('An Error: ' & Choose(Error()=FileSystemErr, FileError(), Error()))
END
New problem over here. Now that the SQL stuff are working, my browses aren’t anymore. Everytime that I do an insertion, update or delete the records on the browse duplicates. The most interesting thing is that it only happens on the view, because on the DB it is absolutely normal.
It normally means the key you are using in the browse is not unique. You can add additional sort items (in the template extension) which will help with uniqueness if you don’t want to use an different key.
The problems with the browses are solved, it really was the key.
Now i’m trying something different. Does anyone here has ever worked with views executing SQL Statements?
I declared a dummy table and on the Local Data - Other Declarations I create the view and projected the fields. When I try to make the view execute a SQL Statement, it returns an error that says: “S1000 - No query has been executed with that handle”