> > Ok. One way that I can think of is that since we have the typeoids
> handily
> > available, we can check the same and see if it is of stringlike type
> > (PGOID_TYPE_CHAR, PGOID_TYPE_NAME, PGOID_TYPE_TEXT, etc..). If yes, then
> we
> > retain the "", else we ignore it. Sounds reasonable?
>
> Yes.
>
>
PFA, version 2 of this patch. We now check if the type of the argument is
stringlike. If yes, we retain the "", else we default to nothing.

Regards,
Nikhils
diff --git a/pgadmin/debugger/dbgTargetInfo.cpp b/pgadmin/debugger/dbgTargetInfo.cpp
index fe50297..bb3d91f 100644
--- a/pgadmin/debugger/dbgTargetInfo.cpp
+++ b/pgadmin/debugger/dbgTargetInfo.cpp
@@ -10,6 +10,7 @@
 //////////////////////////////////////////////////////////////////////////
 
 #include "pgAdmin3.h"
+#include "utils/pgDefs.h"
 
 // wxWindows headers
 #include <wx/wx.h>
@@ -32,6 +33,7 @@ WX_DEFINE_OBJARRAY( wsArgInfoArray );
 #define COL_ARG_MODES    	"argmodes"
 #define COL_ARG_TYPES    	"argtypenames"
 #define COL_ARG_TYPEOIDS    "argtypeoids"
+#define COL_ARG_DEFVALS     "argdefvals"
 #define COL_IS_FUNCTION    	"isfunc"
 #define COL_TARGET_OID    	"target"
 #define COL_PACKAGE_OID    	"pkg"
@@ -86,6 +88,10 @@ dbgTargetInfo::dbgTargetInfo( const wxString &target,  dbgPgConn *conn, char tar
 	m_argTypes 	 = result->getString( wxString(COL_ARG_TYPES, wxConvUTF8));
 	m_argTypeOids = result->getString( wxString(COL_ARG_TYPEOIDS, wxConvUTF8));
 
+	// get arg defvals if they exist
+	if (result->columnExists(wxString(COL_ARG_DEFVALS, wxConvUTF8)))
+		m_argDefVals = result->getString( wxString(COL_ARG_DEFVALS, wxConvUTF8));
+
 	if (result->columnExists(wxString(COL_PACKAGE_OID, wxConvUTF8)))
 		m_isFunction = result->getBool( wxString(COL_IS_FUNCTION, wxConvUTF8));
 	else
@@ -112,6 +118,7 @@ dbgTargetInfo::dbgTargetInfo( const wxString &target,  dbgPgConn *conn, char tar
 	wxStringTokenizer types(m_argTypes, wxT( ",{}" ), wxTOKEN_STRTOK);
 	wxStringTokenizer typeOids(m_argTypeOids, wxT( ",{}" ), wxTOKEN_STRTOK);
 	wxStringTokenizer modes(m_argModes, wxT( ",{}" ), wxTOKEN_STRTOK);
+	wxStringTokenizer defvals(m_argDefVals, wxT( ",{}" ), wxTOKEN_STRTOK);
 
 	// Create one wsArgInfo for each target argument
 
@@ -123,6 +130,7 @@ dbgTargetInfo::dbgTargetInfo( const wxString &target,  dbgPgConn *conn, char tar
 		argCount++;
 
 		wxString	argName = names.GetNextToken();
+		wxString    defVal;
 
 		if( argName.IsEmpty())
 			argName.Printf( wxT( "$%d" ), argCount );
@@ -136,6 +144,14 @@ dbgTargetInfo::dbgTargetInfo( const wxString &target,  dbgPgConn *conn, char tar
 		else if( argInfo.getMode() == wxT( "b" ))
 			m_argInOutCount++;
 
+		// see if this arg has a def value and add if so. If we see an empty
+		// string "", what should we do? Infact "" might be a valid default
+		// value in some cases, so for now store "" too. Note that we will
+		// store the "" only if this is stringlike type and nothing otherwise..
+		defVal = (defvals.GetNextToken()).Strip ( wxString::both );
+		if (argInfo.isValidDefVal(defVal))
+			argInfo.setValue(defVal);
+
 		m_argInfo.Add( argInfo );
 	}
 
@@ -219,3 +235,39 @@ const wxString wsArgInfo::quoteValue()
 	else
 		return(wxString(wxT("'") + m_value + wxT("'")));
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// isValidDefVal()
+//
+//    This function checks if the passed in defvalue is sane or not. If it is
+//    empty, nothing needs to be done. However if the backend returns "", then
+//    we need to entertain this as valid input only for stringlike types. Else
+//    we ignore. Obviously if defval is anything other than "", we need to
+//    honor it
+//
+
+bool wsArgInfo::isValidDefVal(const wxString defValue)
+{
+	if (defValue.IsEmpty())
+		return false;
+
+	if (defValue != wxT("\"\""))
+		return true;
+	else
+	{
+		// return true only if the type is a stringlike type..
+		switch (getTypeOid())
+		{
+			case PGOID_TYPE_CHAR:
+			case PGOID_TYPE_NAME:
+			case PGOID_TYPE_TEXT:
+			case PGOID_TYPE_BPCHAR:
+			case PGOID_TYPE_VARCHAR:
+			case PGOID_TYPE_CSTRING:
+				return true;
+
+			default:
+				return false;
+		}
+	}
+}
diff --git a/pgadmin/debugger/dlgDirectDbg.cpp b/pgadmin/debugger/dlgDirectDbg.cpp
index c3f6240..be31dbe 100644
--- a/pgadmin/debugger/dlgDirectDbg.cpp
+++ b/pgadmin/debugger/dlgDirectDbg.cpp
@@ -783,10 +783,15 @@ void dlgDirectDbg::OnTargetComplete( wxCommandEvent &event )
 		char *state = PQresultErrorField(result, PG_DIAG_SQLSTATE);
 
 		// Don't bother telling the user that he aborted - he already knows!
-		if (state != NULL && strcmp(state, "57014"))
-			wxLogError( wxT( "%s\n" ), wxString(PQerrorMessage(m_conn->getConnection()), wxConvUTF8).c_str());
-		else
-			wxLogInfo( wxT( "%s\n" ), wxString(PQerrorMessage(m_conn->getConnection()), wxConvUTF8).c_str());
+		// Depending on the stage, m_conn might not be set all! so check for
+		// that first
+		if (m_conn)
+		{
+			if (state != NULL && strcmp(state, "57014"))
+				wxLogError( wxT( "%s\n" ), wxString(PQerrorMessage(m_conn->getConnection()), wxConvUTF8).c_str());
+			else
+				wxLogInfo( wxT( "%s\n" ), wxString(PQerrorMessage(m_conn->getConnection()), wxConvUTF8).c_str());
+		}
 	}
 	else
 	{
diff --git a/pgadmin/include/debugger/dbgTargetInfo.h b/pgadmin/include/debugger/dbgTargetInfo.h
index e3fb9f8..4ab8b28 100644
--- a/pgadmin/include/debugger/dbgTargetInfo.h
+++ b/pgadmin/include/debugger/dbgTargetInfo.h
@@ -47,6 +47,7 @@ public:
 		return m_value;    // NOTE: non-const, caller may modifiy value
 	}
 	const wxString   quoteValue();
+	bool isValidDefVal( const wxString defvalue );
 	void  setValue( const wxString &newValue )
 	{
 		m_value = newValue;
@@ -157,6 +158,7 @@ private:
 	wxString	m_argModes;	 // Argument modes
 	wxString	m_argTypes;	 // Argument types
 	wxString	m_argTypeOids; // Argument type OIDs
+	wxString	m_argDefVals;  // Argument default values
 	wxString	m_fqName;	 // Fully-qualified name (schema.package.func or package.func)
 	wxString    m_returnType;// Return type
 	bool	m_isFunction;	 // true->target is a function, false->target is a procedure
-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to