I am currently working on a system that uses an Access database to store a list of url's waiting to be processed. I need to be able to add to, and amend the database, and so, I have derived a class from the CRecordset class called CURLRecordset using the classwizard. In my application, I can succesfully open a CDatabase object in order to connect to the database, but when it comes to opening the actual recordsets associated with it: /* CURLRecordset* unparsed_urls; CDatabase* db; CString sql; */ unparsed_urls = new ( CUnparsed ) ( db ); sql.Format ( "SELECT * FROM urls WHERE status = %d;", STATUS_NOT_CRAWLED ); unparsed_urls->Open ( CRecordset::snapshot, (LPCTSTR)sql ); I get the following exception: "Invalid character value for cast specification on column number 2 (urladdress)" I have traced the source of the exception to the final move() function call in the CRecordset class's Open() method, but I have no idea how to deal with it. My database schema is as follows: TABLE urls = ( long urlid (PRIMARY KEY) VARCHAR(256) urladdress long status long level long keywordid long sourceid ) The header file for the CURLRecordset class is as follows: class CURLRecordset : public CRecordset { public: CURLRecordset(CDatabase* pDatabase = NULL); DECLARE_DYNAMIC(CURLRecordset) // Field/Param Data //{{AFX_FIELD(CURLRecordset, CRecordset) long m_keywordid; long m_level; long m_sourceid; long m_status; CString m_urladdress; long m_urlid; //}}AFX_FIELD // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CURLRecordset) public: virtual CString GetDefaultConnect(); // Default connection string virtual CString GetDefaultSQL(); // Default SQL for Recordset virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support //}}AFX_VIRTUAL // Implementation #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif }; Any help will be greatly appreciated!
Munkijo
Posts
-
Opening a CRecordset derived class problem -
Help needed deriving class from CRecordsetI am currently working on a system that uses an Access database to store a list of url's waiting to be processed. I need to be able to add to, and amend the database, and so, I have derived a class from the CRecordset class called CURLRecordset using the classwizard. In my application, I can succesfully open a CDatabase object in order to connect to the database, but when it comes to opening the actual recordsets associated with it: /* CURLRecordset* unparsed_urls; CDatabase* db; CString sql; */ unparsed_urls = new ( CUnparsed ) ( db ); sql.Format ( "SELECT * FROM urls WHERE status = %d;", STATUS_NOT_CRAWLED ); unparsed_urls->Open ( CRecordset::snapshot, (LPCTSTR)sql ); I get the following exception: "Invalid character value for cast specification on column number 2 (urladdress)" I have traced the source of the exception to the final move() function call in the CRecordset class, but I have no idea how to deal with it. My database schema is as follows: TABLE urls = ( long urlid (PRIMARY KEY) VARCHAR(256) urladdress long status long level long keywordid long sourceid ) The header file for the CURLRecordset class is as follows: class CURLRecordset : public CRecordset { public: CURLRecordset(CDatabase* pDatabase = NULL); DECLARE_DYNAMIC(CURLRecordset) // Field/Param Data //{{AFX_FIELD(CURLRecordset, CRecordset) long m_keywordid; long m_level; long m_sourceid; long m_status; CString m_urladdress; long m_urlid; //}}AFX_FIELD // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CURLRecordset) public: virtual CString GetDefaultConnect(); // Default connection string virtual CString GetDefaultSQL(); // Default SQL for Recordset virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support //}}AFX_VIRTUAL // Implementation #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif }; Any help will be greatly appreciated!
-
Problem with CString::Replace ( LPCTSTR lpszOld, LPCTSTR lpszNew );What??? No, where it says HTMLfile->Replace (" ", " "); the first string is actually a non-braking space character - In the while loop, it's meant to have two spaces between the first seyt of inverted commas, and one in the second set.
-
Problem with CString::Replace ( LPCTSTR lpszOld, LPCTSTR lpszNew );It's not a very elegant method, but the code is: void CParser::StandardiseHTML ( CString* HTMLfile ) { HTMLfile->Replace ("@", "@"); HTMLfile->Replace ('\n', ' '); HTMLfile->Replace ('\t', ' '); HTMLfile->Replace (" ", " "); while ( HTMLfile->Replace (" ", " ") != 0 ); HTMLfile->Replace (" =", "="); HTMLfile->Replace ("= ", "="); HTMLfile->MakeUpper (); } It manages to get into trouble with the statement HTMLfile->Replace (" ", " ");
-
Problem with CString::Replace ( LPCTSTR lpszOld, LPCTSTR lpszNew );I have a CString type variable with a large HTML file in it. When I attempt to replace all occurrances of a character with another characer, it works fine, however, if I attempt to replace a string ("= ") with another string ("="), it appears to get stuck in some endless loop somewhere. I have left it running for hours, and it is still stuck at the same replace statement. Is there something I'm missing?