What am I doing wrong?

Money Manager Ex Development related posts

What am I doing wrong?

Postby omalleypat » Sat Nov 14, 2009 6:30 pm

I cannot figure this out for the life of me...I'm trying to create a new function to filter payees by name. Here's the abbreviated diff of what I did:

Code: Select all
macbook:mmex_src pom$ svn diff
Index: src/dbwrapper.cpp
===================================================================
--- src/dbwrapper.cpp   (revision 781)
+++ src/dbwrapper.cpp   (working copy)
@@ -2128,7 +2128,23 @@
     return amt;
 }
 
+wxArrayString mmDBWrapper::filterPayees(wxSQLite3Database* db, wxString patt)
+{
+   wxArrayString flist;
+   wxString sql;
+   sql.Printf(wxT("select PAYEENAME from PAYEE_V1 where PAYEENAME LIKE '%s%%' ORDER BY PAYEENAME"),patt.c_str());
+   
+   wxSQLite3Statement st = db->PrepareStatement(sql);
+    wxSQLite3ResultSet q1 = st.ExecuteQuery();
+   while (q1.NextRow())
+   {
+      flist.Add(q1.GetString(wxT("PAYEENAME")));
+   }
+   
+   return flist;
+}

Index: src/dbwrapper.h
===================================================================
--- src/dbwrapper.h   (revision 781)
+++ src/dbwrapper.h   (working copy)
@@ -80,7 +80,8 @@
 bool updatePayee(wxSQLite3Database* db, const wxString& payeeName, int payeeID, int categID, int subcategID);
 bool deletePayeeWithConstraints(wxSQLite3Database* db, int payeeID);
 double getAmountForPayee(wxSQLite3Database* db, int payeeID, bool ignoreDate, wxDateTime dtbegin, wxDateTime dtEnd);
-
+wxArrayString filterPayees(wxSQLite3Database* db, wxString patt);
+   
 /* Category Table API */
 bool deleteCategoryWithConstraints(wxSQLite3Database* db, int categID);
 bool deleteSubCategoryWithConstraints(wxSQLite3Database* db, int categID, int subcategID);


Index: src/payeedialog.cpp
===================================================================
--- src/payeedialog.cpp   (revision 781)
+++ src/payeedialog.cpp   (working copy)
+   wxArrayString filtd = mmDBWrapper::filterPayees(core_->db_.get(),textCtrl_->GetValue());



It compiles ok, but on launch, I get this:
Code: Select all
Assertion failed: (px != 0), function operator->, file mmex_src/include/boost/shared_ptr.hpp, line 375.
Program received signal:  “SIGABRT”.
sharedlibrary apply-load-rules all


Can anyone see something obviously wrong here? I'm not really a C++ programmer and this has got me stumped!
omalleypat
MMEX Developer
 
Posts: 120
Joined: Tue Jul 28, 2009 4:34 pm
Location: Atchison, KS

Re: What am I doing wrong?

Postby Vadim » Sun Nov 15, 2009 8:58 am

First of all read this post: viewtopic.php?f=7&t=614
I modified all SQL across all sources to remove literals from SQL. Please, don't do the same errors in new code.

The same error now present in trunk. You are trying to use database interface before its initialization.
Vadim
MMEX Developer
 
Posts: 159
Joined: Mon Aug 03, 2009 1:35 am

Re: What am I doing wrong?

Postby Vadim » Sun Nov 15, 2009 9:08 am

mmDBWrapper::filterPayees(wxSQLite3Database* db, wxString patt)
Learn C++, passing wxString by value is wrong choice, use "const wxString&". And check pointer db before dereference it. In future I will change all signatures like function_xxx(wxSQLite3Database* db, ... to function_xxx(boost::shared_ptr<wxSQLite3Database> db, ...
This will prevent dereferencing of zero pointers.
Vadim
MMEX Developer
 
Posts: 159
Joined: Mon Aug 03, 2009 1:35 am


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest