IDE error running postgreSQL

Post

Posted
Rating:
#1 (In Topic #1551)
Regular
monteiro is in the usergroup ‘Regular’
 Good morning.
On Gambas 3.20  project I have the following SQL string:

"SELECT numero, data_venda, cliente, setor, prazo,
       (data_venda + (prazo * INTERVAL '1 day')) AS test_data_sum
FROM vendas
WHERE prazo IS NOT NULL
  AND setor = 'Laudos'
  AND faturado IS FALSE
  AND  (data_venda + (prazo * INTERVAL '1 day')) = CURRENT_DATE;"

1 - None of the fields in the table is Null or the wrong type.
2 - This query runs well, without error if typed in connection console and returns the right results.

But the very same query string, when running in the IDE produces the error message:
"Type mismatch. Expected number, date or string but found Void."

Any tips? I don't know what to do

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
how are you using that string in your code ... show us some Gambas code using that string ,,,, then someone may be able to help .
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
monteiro is in the usergroup ‘Regular’

Code (gambas)

  1. With mGlobal
  2.   .rs=.db.exec("SELECT numero, data_venda, cliente, setor, prazo,(data_venda + (prazo * INTERVAL '1 day') - INTERVAL '2 days') AS final_calculated_date From vendas Where prazo IS NOT NULL And setor = 'Laudos'  And faturado IS FALSE  AND ((data_venda + (prazo * INTERVAL '1 day') - INTERVAL '2 days') = CURRENT_DATE + INTERVAL '2 days');") ' <-- this line produces the error message
  3.  ' more code

Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
this might give you some help … I don't use postgre   I have limited use of SQLite
this is my handleing module … might give you a hint at the syntax  :

Code (gambas)

  1. ' Gambas module file
  2.  
  3. '' Module file to handle SQLite file
  4. '' SQLite  file handeling subroutines
  5. '' writen by  GrayGhost4  Marvin Clavey  June 2022   modified  through  2025
  6.  
  7. Private sadata As String[]
  8.  
  9. Public Sub GetFileData(sfilename As String, scolumnName As String) As String[]
  10.    
  11.    With $con
  12.       Try .Close()             ' Close the connection. The try allows it to fail without error
  13.       .Type = "sqlite3"        ' Defines the type of connection
  14.       .Host = Application.path ' Host will be the path where the sqlite db file is
  15.       .Name = "data.SQL"  '  database name is the name of the database file"
  16.       Try .Open()                  ' We activate and open the connection, the try is to allow an error
  17.       If Error Then Print "Cannot Open Database. Error = "; Error.Text
  18.       RS = .Exec("Select * From " & sfilename)
  19.    End With
  20.    
  21. Return RS.All(scolumnName)   ' return all the data from one column
  22.    
  23.  
  24. Public Sub GetRecordData(sFileName As String, sFileColumn As String, sFileIndex As String) As String[]
  25.    
  26.    Dim saInfo As New String[]    ' must have "NEW" or you will get a null error with .add
  27.    Dim obj As ResultField
  28.    
  29.    RS = $con.Exec("Select * From" & Quote(sFileName) & "where" & Quote(sFileColumn) & "like" & Quote(sFileIndex))
  30.  
  31.  
  32.    For Each obj In RS.Fields
  33.       sainfo.Add(RS[obj.Name])
  34.    Next
  35.    Return saInfo
  36.    
  37.  
  38. Public Sub UpdateFileData(sFileName As String, sFileIndex As String, saInfo As String[])
  39.    
  40.    Dim saCommand As String  
  41.    Dim obj As ResultField
  42.    
  43.    saInfo = saInfo.Reverse()
  44.    For Each obj In RS.Fields                'assemble the update command "column" = "data"
  45.       saCommand &= Quote(obj.Name) & " = " & Quote(saInfo.Pop()) & ","
  46.    Next
  47.    saCommand = Left(saCommand, -1)        ' remove the last ","  from saCommand string
  48.    $con.Exec("update" & Quote(sFileName) & "set" & saCommand & "where accname = " & Quote(sFileIndex))
  49.    
  50. '
  51.  
  52. Public Sub UpdateFileData(sFileName As String, sFileIndex As String, saInfo As String[])
  53.    
  54.    Dim saCommand As String  
  55.    Dim obj As ResultField
  56.    
  57.    saInfo = saInfo.Reverse()
  58.    For Each obj In RS.Fields                'assemble the update command "column" = "data"
  59.       saCommand &= Quote(obj.Name) & " = " & Quote(saInfo.Pop()) & ","
  60.    Next
  61.    saCommand = Left(saCommand, -1)        ' remove the last ","  from saCommand string
  62.    $con.Exec("update" & Quote(sFileName) & "set" & saCommand & "where accname = " & Quote(sFileIndex))
  63.    
  64.  
  65. Public Sub InsertNewRecord(sFileName As String)
  66.    
  67.    Dim sNewRecord As String
  68.    
  69.    For Each obj As Object In RS.Fields    ' This assenbles the File column names it to A string
  70.       sNewRecord &= Quote(obj.Name) & "," ' to insert into a blank record to be edited later
  71.    Next
  72.    sNewRecord = Left(sNewRecord, -1)         'remove the last ","  from the string
  73.    sNewRecord = Replace(sNewRecord, "accname", "newAcc" & Str(Rand(20, 100)))  ' replace first field (random) for index
  74.    $con.Exec("INSERT INTO " & Quote(sFileName) & " VALUES (" & sNewRecord & ")")
  75.    
  76.  
  77. Public Sub deleatOneRecord(sFileName As String, sFileField As String, sFileIndex As String)
  78.  
  79.       $con.Exec(DB.Subst("delete from [&1] where  '&2'  =  &3 ", sFileName, sFileField, sFileIndex))
  80.  
  81.  
  82. Public Sub InsertNewRecord(sFileName As String)
  83.    
  84.    Dim sNewRecord As String
  85.    
  86.    For Each obj As Object In RS.Fields    ' This assenbles the File column names it to A string
  87.       sNewRecord &= Quote(obj.Name) & "," ' to insert into a blank record to be edited later
  88.    Next
  89.    sNewRecord = Left(sNewRecord, -1)         'remove the last ","  from the string
  90.    sNewRecord = Replace(sNewRecord, "accname", "newAcc" & Str(Rand(20, 100)))  ' replace first field (random) for index
  91.    $con.Exec("INSERT INTO " & Quote(sFileName) & " VALUES (" & sNewRecord & ")")
  92.    
  93.  
  94. Public Sub deleatOneRecord(sFileName As String, sFileField As String, sFileIndex As String)
  95.  
  96.       $con.Exec(DB.Subst("delete from [&1] where  '&2'  =  &3 ", sFileName, sFileField, sFileIndex))
  97.  
  98.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
using the Subst()  is just a better way of enclosing fields in " " .  this is the suggested way .

Code (gambas)

  1.       $con.Exec(DB.Subst("delete from [&1] where  '&2'  =  &3 ", sFileName, sFileField, sFileIndex))
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
You also have to use the proper data base handling module.

<IMG src="/home/mhc/Pictures/Screenshots/Screenshot%20From%202025-07-04%2011-27-27.png"> </IMG>

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
monteiro is in the usergroup ‘Regular’
Thanks for your answer. But the error is not in the syntax (because it works fine if executed directly) nor in the module used. Several other routines for accessing the PostgreSQL database already exist.

In short, why does the same query works in the console but give this error in the IDE?

Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 Several other routines for accessing the PostgreSQL database already exist.

So why not use those routines ?


works in the console

what is the console ??
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 What is mGlobal.rs and mGlobal.db when that line is executed? IOW has the result and the connection been established? I see no other problems with your SQL statement.
b

Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
Add this to your sub before any other code in that sub

Code

db.Debug = True

and watch the console for the output. You can comment it out when debugging isn't needed.

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#11
Regular
monteiro is in the usergroup ‘Regular’

thatbruce said

What is mGlobal.rs and mGlobal.db when that line is executed? IOW has the result and the connection been established? I see no other problems with your SQL statement.
b

The connection to PostgreSQL is initially established in a login window.
After successful login, a main window is loaded. And several SQL queries are successfully executed.
This has been working fine for quite some time and is still ok.
I have now added this new SQL query and it is the only one that returns this error that makes no sense to me.
Also, if I execute this same SQL query manually in connection1 within the project, it works without error. The error only occurs when the program is running.

It seems that the structure of THIS SQL query is supported in connection1 but, when the program is running, another control is used and this one does not support the structure of THIS SQL query well.

Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
monteiro is in the usergroup ‘Regular’
 Grayghost, The other routines I mentioned are other SQL queries that perform other tasks and are working fine, only THIS SQL query returns this error.

sholzy: I'll try to use debug in this sub. I'll only be able to do this on Monday

Online now: No Back to the top

Post

Posted
Rating:
#13
Regular
monteiro is in the usergroup ‘Regular’
Debug did not show anything. Just the same error message appeared.
But this is a bug for sure, because the SQL statement returns the right values with no errors.
I tested it by not doing the math in the query but in the following way:

.rs = .db.Exec("Select numero,data_venda,prazo,cliente from vendas Where faturado IS FALSE And setor ='Laudos'
If Format(DateAdd(.rs!data_venda, gb.Day, (.rs!prazo - 2)), "ddmmyy") = Format(Now, "ddmmyy") Then

And no errors….

But if I put the calculations inside the SQL statement, the recordset returns that same error (a 'void' value).

Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 Did you look at the values of all the variables … I think debug show them,   are they all properly initialize it this sub?
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’

monteiro said

Debug did not show anything. Just the same error message appeared.
But this is a bug for sure, because the SQL statement returns the right values with no errors.
I tested it by not doing the math in the query but in the following way:

.rs = .db.Exec("Select numero,data_venda,prazo,cliente from vendas Where faturado IS FALSE And setor ='Laudos'
If Format(DateAdd(.rs!data_venda, gb.Day, (.rs!prazo - 2)), "ddmmyy") = Format(Now, "ddmmyy") Then

And no errors….

But if I put the calculations inside the SQL statement, the recordset returns that same error (a 'void' value).
You say you are on 3.20.
1. What exact version of the 3.20 series?
2. Are you using gb.db2 component or gb.db?

There have been bugs in 3.20 in gb.db2 component as discovered in this topic  :arrow: https://forum.gambas.one/viewtopic.php?t=1981
Somewhere past halfway into the topic a gb,db2 bug seemed to be the cause. This was in Gambas 3.20.2.
So, maybe you're still on the buggy 3.20 version?

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#16
Regular
monteiro is in the usergroup ‘Regular’
 My version is 3.20.4
In it gb.db appears as 'deprecated' and so I'm using gb.db2
I'll check out this topic you mentioned, but I think there must be some minor bugs left.

Online now: No Back to the top

Post

Posted
Rating:
#17
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Only one guess…
the IS NOT NULL in your original post is the only thing I could see which may have been incorrectly substituted.
Did using db.debug=true not print the actual SQL that was used?
b

p.s. This could well be a gb.db2 bug as I have previously reported errors in this area.

Online now: No Back to the top

Post

Posted
Rating:
#18
Regular
monteiro is in the usergroup ‘Regular’
 Looks like the error occurs before the variables are filled..
The PostgreSQL server is returning the values correctly.
gb.db2 doesn't seem to be interpreting the data correctly when performing calculations involving dates.
When I perform these calculations within Gambas, they work correctly.

Online now: No Back to the top

Post

Posted
Rating:
#19
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’

monteiro said

Looks like the error occurs before the variables are filled..
The PostgreSQL server is returning the values correctly.
gb.db2 doesn't seem to be interpreting the data correctly when performing calculations involving dates.
When I perform these calculations within Gambas, they work correctly.
Maybe it is time to report it as a bug on the bugtracker  :arrow: https://gambaswiki.org/bugtracker

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top
1 guest and 0 members have just viewed this.