New topic: 

OpenSuSE 11.4 + PostgreSQL 9.0.3 Returns Nil after connect

<http://forums.realsoftware.com/viewtopic.php?t=41613>

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        McDian          Post subject: OpenSuSE 11.4 + PostgreSQL 9.0.3 
Returns Nil after connectPosted: Mon Nov 28, 2011 7:31 pm                       
  
Joined: Fri Sep 14, 2007 5:00 pm
Posts: 362                Okay, so I am re-writing an application to use 
PostgreSQL as I have not been successful in getting Crystal Reports to connect 
to my SQLite database on my Linux system. Also I am noticing some minor errors 
that are cropping up due to SQLite's design.

So I found a great source to connect and I am getting the message that a 
connection has been made. But when I try to query a table that has data in it, 
I get a NilObjectException thrown.

Just a note this is a very rough application I am working with right now, 
mainly so I can learn how to interact with the PostgreSQL database and so 
forth. So the code I will post now is basically ALPHA for learning.

Under App.Open I have the following code:

Code:  // Variable declaration(s)
  Dim dbPgsqlTst As PostgreSQLDatabase = New PostgreSQLDatabase
  
  // Define the location and load the variable
  dbPgsqlTst.Host = "127.0.0.1"
  dbPgsqlTst.Port = 5432
  dbPgsqlTst.UserName = "XXXXXX" // "postgres" is the default admin user name.
  dbPgsqlTst.Password = "XXXXXX"
  dbPgsqlTst.DatabaseName = "dbTest" // Postgres supports multiple databases. 
Which one do you want? Default is name the same name as user, such as 
'postgres'.
  
  ' Connection attempt...
  Dim connStat As String
  
  If(dbPgsqlTst.Connect) Then
  connStat = "Database connection established."
  
  Else
  ' Well there is a problem Jack!
  connStat = "An error occurred when connecting to database server. Code: " + 
Str(dbPgsqlTst.ErrorCode) + " " + dbPgsqlTst.ErrorMessage
  
  End If
  
  MsgBox connStat

This is where I get the connection has happened message.

Next I have a module called modDbConn and it contains a Method and a Property.

modDbConn.mthGetAppFldr
Parameters:
Return Type: FolderItem
Access: Global
Code:  // Preliminary code...
  
  ' :-- NONE DEFINED --:
  
  // Variable declarations...
  Dim fldrItem As FolderItem = GetFolderItem("")
  
  // Function(s)...
  #If DebugBuild Then fldrItem = fldrItem.Parent
  
  Return fldrItem

modDbConn.Properties
Declaration:dbPgsqlTst As PostgreSQLDatabase
Access: Global

So none of the above is throwing any errors and appears to be working. Now onto 
the next element, I have another Module called modSel it contains only a single 
Method at this time:

modSel.mthMeter
Parameters: stMetId As String
Return Type: RecordSet
Access: Protected

Code:  Dim recSet As RecordSet
  
  If(dbPgsqlTst.Connect) = True Then
  If(stMetId) = "" Then
  recSet = dbPgsqlTst.SQLSelect("SELECT * FROM tblMets ORDER BY metId")
  
  Else
  recSet = dbPgsqlTst.SQLSelect("SELECT * FROM tblMets WHERE metId='" + stMetId 
+ "'")
  
  End If
  
  If(recSet) = Nil Then
  Beep
  MsgBox "There was an error with the meter select query: " + 
Str(dbPgsqlTst.ErrorCode) + EndOfLine.Windows + EndOfLine.Windows _
  + dbPgsqlTst.ErrorMessage  + EndOfLine.Windows + EndOfLine.Windows + "This 
error was generated from: modSel.mthMeter"
  Exit
  
  Else
  Return recSet
  
  End If
  
  Else
  If(dbPgsqlTst.Error) Then
  Beep
  MsgBox "An error with the database has occured! " + Str(dbPgsqlTst.ErrorCode) 
 + EndOfLine.Windows + EndOfLine.Windows _
  + dbPgsqlTst.ErrorMessage
  Exit
  
  End If
  
  MsgBox "A connection error has occurred and the database is not responding! " 
+ Str(dbPgsqlTst.ErrorCode)  + EndOfLine.Windows _
  + EndOfLine.Windows + dbPgsqlTst.ErrorMessage
  
  End If

This is where the error is being thrown from. Now this is being called by a 
Window that has a ListBox on it, the ListBox calls modSel.mthMeter with the 
code below:

Window1.Listbox1.Open
Code:  // Headings and sizes
  Me.ColumnWidths = "15%,25%,*"
  
  Me.Heading(0) = "Met ID"
  Me.Heading(1) = "Meter Name"
  Me.Heading(2) = "Seq#"
  
  Dim recSet As RecordSet = modSel.mthMeter("")
  
  While not recSet.EOF
  Me.AddRow(recSet.IdxField(3).StringValue)
  Me.Cell(Me.LastIndex, 1) = recSet.IdxField(4).StringValue
  Me.Cell(Me.LastIndex, 1) = recSet.IdxField(2).StringValue
  
  recSet.MoveNext
  
  Wend
  
  recSet.Close

What am I doing wrong?   
                             Top                timhare          Post subject: 
Re: OpenSuSE 11.4 + PostgreSQL 9.0.3 Returns Nil after connePosted: Mon Nov 28, 
2011 8:47 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 10509
Location: Portland, OR  USA                The problem is right here:
Code:Dim dbPgsqlTst As PostgreSQLDatabase = New PostgreSQLDatabase

Instead of using the global property from your module, you're dimming a local 
variable of the same name.  You're setting the local var and leaving the global 
one nil.

Change that line to
Code:dbPgsqlTst = New PostgreSQLDatabase
   
                             Top                McDian          Post subject: 
Re: OpenSuSE 11.4 + PostgreSQL 9.0.3 Returns Nil after connePosted: Mon Nov 28, 
2011 9:24 pm                         
Joined: Fri Sep 14, 2007 5:00 pm
Posts: 362                Thank you! It now runs but doesn't return a value, 
there are a verified 1,586 records in the table I am trying to pull data from 
but nothing is being returned?   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to