ODBC - Execution of instruction " insert " - dBas

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

ODBC - Execution of instruction " insert " - dBas

Post by prokicki » Sun May 08, 2005 8:54 pm

I own connection with base, creature table, (I can insert data without problem ), However, problem beguile with execution of select instruction.
Code below, engine throws out error me :

"Not enough parameters , 9 expect "

(dBase)

( similar there is as I will execute query:
"SELECT * FROM Tabela WHERE
Inny_Symbol = 'COS' "
At use of class wxDbTable::QueryBySqlStmt .)

I will add, that everything there is in documentation so as exactly

Code: Select all

const wxChar TableName[] = wxT("Tabela");


  wxChar PSymbol[100+1];
 (...)

  wxChar PInny_Symbol[50+1];



     DbConnectInf = new wxDbConnectInf(NULL, wxT("dBase"));



  if(!DbConnectInf || !DbConnectInf->GetHenv())
    {

        wxMessageBox(wxDbLogExtendedErrorMsg("Błąd polączenioa ODBC:", 
table->GetDb(),0,0));
    };





  db = wxDbGetConnection(DbConnectInf);

   if(!db)
    {
        wxMessageBox("Błąd Połączenia z bazą");
    };



  table = new wxDbTable(db, TableName, numTableColumns, wxT(""), 
!wxDB_QUERY_ONLY, wxT(""));

  table->SetColDefs(0, wxT("Symbol"), DB_DATA_TYPE_VARCHAR, PSymbol,
                   SQL_C_CHAR, sizeof(PSymbol), true, true);

  (...)
   table->SetColDefs(21, wxT("Inny_Symbol"), DB_DATA_TYPE_VARCHAR, 
PInny_Symbol,
                   SQL_C_CHAR, sizeof(PInnySymbol), true, true);


        if(!table->CreateTable(true))
    {

        wxMessageBox(wxDbLogExtendedErrorMsg("Błąd utworzenia tabeli:", 
table->GetDb(),0,0));
    };

    if(!table->Open())
    {

        wxMessageBox(wxDbLogExtendedErrorMsg("Błąd otwarcia tabeli:", 
table->GetDb(),0,0));
    };

   table->SetWhereClause(wxT("Inny_Symbol= 'cos'"));

   table->SetFromClause(wxT(""));


    if(!table->Query())
    {
     wxMessageBox(wxDbLogExtendedErrorMsg("Błąd wykonania zapytania:", 
table->GetDb(),0,0));
    }

P.
forum C++ in polish
cpp.g5.pl

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4524
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Sun May 08, 2005 9:01 pm

Hi, prokicki,
Could you post the value of table->Query(), please?

Thank you.
Last edited by ONEEYEMAN on Sun May 08, 2005 9:48 pm, edited 1 time in total.

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Sun May 08, 2005 9:26 pm

SQL state = 07001
Native Error Code = -3010
Error Msg As highly
forum C++ in polish
cpp.g5.pl

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Sun May 08, 2005 9:29 pm

ps

Twenty two cells are in table .

I use with translator on-line
So, we can not be apprehended
forum C++ in polish
cpp.g5.pl

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4524
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Sun May 08, 2005 9:50 pm

Could you please post the query?
And will you be able to execute it from MS ACCESS, for example?

Thank you.

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Sun May 08, 2005 10:00 pm

query is very simple, Anyway, the same is in documentation

My QUERY:

Code: Select all

wxString sqlStmt;
 
sqlStmt= " SELECT * FROM Tabela WHERE Inny_Symbol = 'COS' ";
tabela->QueryBySqlStmt(sqlStmt);
or

Code: Select all

table->SetWhereClause(wxT("Inny_Symbol= 'cos'"));

   table->SetFromClause(wxT(""));


    if(!table->Query())
    {
     wxMessageBox(wxDbLogExtendedErrorMsg("Błąd wykonania zapytania:",
table->GetDb(),0,0));
    }




(in documentation:
// Incomplete code samples

Code: Select all

 wxString sqlStmt;
    sqlStmt = "SELECT * FROM PARTS WHERE STORAGE_DEVICE = 'SD98' \
               AND CONTAINER = 12";
    // Query the records using the SQL SELECT statement above
    parts->QueryBySqlStmt(sqlStmt);
    // Display all records queried
    while(parts->GetNext())
        dispPart(&parts);
)

I don't have MS ACCES

P.
forum C++ in polish
cpp.g5.pl

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4524
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Sun May 08, 2005 11:27 pm

Hi, prokicki,
How many fields you have in the table "Tabela"?
How many variables you defined to hold the values of the fields?

This is not about cells...

[quote
Twenty two cells are in table .
[/quote]

:D

The SQLState=07001 reporting that this is you mismatch.

Thank you.

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Mon May 09, 2005 10:26 am

Fields 22, all is type "DB_DATA_TYPE_VARCHAR "

So, it for after behind it, when it inscribes "SQL_C_WXCHAR" in function
"SetColDefs"
Compiler says, that alternate variable is defined not,
but When I inscribe "SQL C CHAR", there is ok.

P.
forum C++ in polish
cpp.g5.pl

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Mon May 09, 2005 10:29 am

ps.

Fields have length from 51 for 100
forum C++ in polish
cpp.g5.pl

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4524
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Mon May 09, 2005 5:40 pm

Hi, prokicki,
You are writing the program using the wxWidgets, right? Which means that you somewhere defined the array of variables to hold the values of the fields in the database, right? Would you post this array definition, please?
Also, what is the type of the data fields in the table "Tablea"? And what kind of DB you are using: dBase, or....?

Thank you.

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Mon May 09, 2005 8:19 pm

You are writing the program using the wxWidgets, right?
YEAP
And what kind of DB you are using: dBase, or....?
..or dBase :-)

Later with "Firerbird" and "PostgreSQL", but
I will revel to configuration later.
While that, I use with dBase.

Code: Select all

wxDbConnectInf  *DbConnectInf = NULL;

wxDb *db = NULL; 

wxDbTable *table = NULL;


 
 
const UWORD numTableColumns = 22;
  
const wxChar TableName[] = wxT("Tabela");
  
  //pola tabeli Firma
  wxChar P1[100+1];
  wxChar P2[100+1];
  wxChar P3[100+1];
  wxChar P4[50+1];
  wxChar P5[100+1];
  wxChar P6[100+1];
  wxChar P7[100+1];
  wxChar P8[100+1];
  wxChar P9[200+1];
  wxChar P10[200+1];
  wxChar P11[200+1];
  wxChar P12[50+1];
  wxChar P13[100+1];
  wxChar P14[200+1];
  wxChar P15[100+1];
  wxChar P16[100+1];
  wxChar P17[100+1];
  wxChar P18[200+1];
  wxChar P19[100+1];
  wxChar P20[100+1];
  wxChar P21[100+1];
  wxChar P22[50+1];    
       
             
  
  
  

  
    DbConnectInf = new wxDbConnectInf(NULL, wxT("dbase"), wxT(""), wxT(""));
  
  
  
  if(!DbConnectInf || !DbConnectInf->GetHenv())
    {
       
        wxMessageBox(wxDbLogExtendedErrorMsg("Błąd polączenioa ODBC:", table->GetDb(),0,0));
    };    
  
  
  

  
  db = wxDbGetConnection(DbConnectInf);
  
   if(!db)
    {
        wxMessageBox("Błąd Połączenia z bazą");
    };    
  
  
  
  
  
  
  table = new wxDbTable(db, TableName, numTableColumns, wxT(""), !wxDB_QUERY_ONLY, wxT(""));
 
  table->SetColDefs(0, wxT("s1l"), DB_DATA_TYPE_VARCHAR, P1, 
                   SQL_C_CHAR, sizeof(P1l), true, true);
                   
   table->SetColDefs(1, wxT("s2"), DB_DATA_TYPE_VARCHAR, P2, 
                   SQL_C_CHAR, sizeof(P2), true, true);
                   
                     
                       
   table->SetColDefs(2, wxT("s3"), DB_DATA_TYPE_VARCHAR, P3, 
                   SQL_C_CHAR, sizeof(P3), true, true);
                   
   table->SetColDefs(3, wxT("s4"), DB_DATA_TYPE_VARCHAR, P4, 
                   SQL_C_CHAR, sizeof(P4), true, true);
                   
     
                      
                       
   table->SetColDefs(4, wxT("s5"), DB_DATA_TYPE_VARCHAR, P5, 
                   SQL_C_CHAR, sizeof(P5), true, true);
                   
   table->SetColDefs(5, wxT("s6"), DB_DATA_TYPE_VARCHAR, P6, 
                   SQL_C_CHAR, sizeof(P6), true, true);
                   
    
                      
                       
   table->SetColDefs(6, wxT("s7"), DB_DATA_TYPE_VARCHAR, P7, 
                   SQL_C_CHAR, sizeof(P7), true, true);
                   
   table->SetColDefs(7, wxT("s8"), DB_DATA_TYPE_VARCHAR, P8, 
                   SQL_C_CHAR, sizeof(P8), true, true);
                   
                      
                       
   table->SetColDefs(8, wxT("s9"), DB_DATA_TYPE_VARCHAR, P9, 
                   SQL_C_CHAR, sizeof(P9), true, true);
                   
   table->SetColDefs(9, wxT("s10"), DB_DATA_TYPE_VARCHAR, P10, 
                   SQL_C_CHAR, sizeof(P10), true, true);
                   
                      
                       
   table->SetColDefs(10, wxT("s11"), DB_DATA_TYPE_VARCHAR, P11, 
                   SQL_C_CHAR, sizeof(P11), true, true);
                   
   table->SetColDefs(11, wxT("s12"), DB_DATA_TYPE_VARCHAR, P12, 
                   SQL_C_CHAR, sizeof(P12), true, true);
                   
                      
                       
   table->SetColDefs(12, wxT("s13"), DB_DATA_TYPE_VARCHAR, P13, 
                   SQL_C_CHAR, sizeof(P13), true, true);
                   
   table->SetColDefs(13, wxT("s14"), DB_DATA_TYPE_VARCHAR, P14, 
                   SQL_C_CHAR, sizeof(P14), true, true);
                   
                      
                       
   table->SetColDefs(14, wxT("s15"), DB_DATA_TYPE_VARCHAR, P15, 
                   SQL_C_CHAR, sizeof(P15), true, true);
                   
   table->SetColDefs(15, wxT("s16"), DB_DATA_TYPE_VARCHAR, P16, 
                   SQL_C_CHAR, sizeof(P16), true, true);
                   
                      
                       
   table->SetColDefs(16, wxT("s17"), DB_DATA_TYPE_VARCHAR, P17, 
                   SQL_C_CHAR, sizeof(P17), true, true);
                   
   table->SetColDefs(17, wxT("s18"), DB_DATA_TYPE_VARCHAR, P18, 
                   SQL_C_CHAR, sizeof(P18), true, true);
                   
                      
                       
   table->SetColDefs(18, wxT("s19"), DB_DATA_TYPE_VARCHAR, P19, 
                   SQL_C_CHAR, sizeof(P19), true, true);
                   
   table->SetColDefs(19, wxT("s20"), DB_DATA_TYPE_VARCHAR, P20, 
                   SQL_C_CHAR, sizeof(P20), true, true);
                   
                      
                       
   table->SetColDefs(20, wxT("s21"), DB_DATA_TYPE_VARCHAR, P21, 
                   SQL_C_CHAR, sizeof(P21), true, true);
                   
   table->SetColDefs(21, wxT("s22"), DB_DATA_TYPE_VARCHAR, P22, 
                   SQL_C_CHAR, sizeof(P22), true, true);
                   
                      
                                     
      
    
    if(!table->CreateTable(true))
    {
       
        wxMessageBox(wxDbLogExtendedErrorMsg("Błąd utworzenia tabeli:", table->GetDb(),0,0));
    };    


    if(!table->Open())
    {
       
        wxMessageBox(wxDbLogExtendedErrorMsg("Błąd otwarcia tabeli:", table->GetDb(),0,0));
    };    
    
  
   wxStrcpy(P1, wxT("Moja druga wartość"));
    wxStrcpy(P2, wxT("Moja druga wartość"));
    wxStrcpy(P3, wxT("Moja pierwsza wartość"));
    wxStrcpy(P4, wxT("Moja druga wartość"));
    wxStrcpy(P5, wxT("Moja pierwsza wartość"));
    wxStrcpy(P6, wxT("Moja druga wartość"));
    wxStrcpy(P7, wxT("Moja pierwsza wartość"));
    wxStrcpy(P8, wxT("Moja druga wartość"));
    wxStrcpy(P9, wxT("Moja pierwsza wartość"));
    wxStrcpy(P10, wxT("Moja druga wartość"));
    wxStrcpy(P11, wxT("Moja pierwsza wartość"));
    wxStrcpy(P12, wxT("Moja druga wartość"));
    wxStrcpy(P13, wxT("NIE"));
    wxStrcpy(P14, wxT("Moja kt
forum C++ in polish
cpp.g5.pl

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4524
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Mon May 09, 2005 9:30 pm

Hi,
As far as I understood you code you inserted the record in the table, and from what I understand the "INSERT" query worked fine. It's a "SELECT" query that is not working.
Now, I don't see anything wrong with you code. The only other suggestion I would make is if you try to clear the fields by calling "table->ClearMember( true );"
Also, what kind of error you got from compiler when you specify the SQL_C_WXCHAR type?

Don't worry we will figure it out..... ;-)

BTW My name is Igor....... :D

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Tue May 10, 2005 11:15 am

Hi

As far as I understood you code you inserted the record in the table, and from what I understand the "INSERT" query worked fine. It's a "SELECT" query that is not working.
Exactly
Also, what kind of error you got from compiler when you specify the SQL_C_WXCHAR type?
at compilation I receive message :

156 C:\Documents and Settings\prokicki\Pulpit\App\main.cpp `SQL_C_WXCHAR' undeclared (first use this function)


BTW
I receive caution always :
153 C:\Documents and Settings\prokicki\Pulpit\App\main.cpp [Warning] `__comp_ctor' is deprecated (declared at c:/dev-cpp/include/wx/dbtable.h:192)

in line:

Code: Select all

table = new wxDbTable(db, TableName, numTableColumns, wxT(""), !wxDB_QUERY_ONLY, wxT(""));
The only other suggestion I would make is if you try to clear the fields by calling "table->ClearMember( true );"
What place in exactly?


P.

ps
I use wxDev 6.4, but without RADu-u because there is out of order
forum C++ in polish
cpp.g5.pl

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4524
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Tue May 10, 2005 5:59 pm

Hi,
at compilation I receive message :

156 C:\Documents and Settings\prokicki\Pulpit\App\main.cpp `SQL_C_WXCHAR' undeclared (first use this function)
What version of wxWindows you are using?
The only other suggestion I would make is if you try to clear the fields by calling "table->ClearMember( true );"

What place in exactly?
Right after the line "table->GetDb()->CommitTrans();"

Thank you.

prokicki
Knows some wx things
Knows some wx things
Posts: 47
Joined: Fri Jan 21, 2005 9:53 am
Contact:

Post by prokicki » Tue May 10, 2005 8:44 pm

hi
ONEEYEMAN wrote:
What version of wxWindows you are using?




wxWidgets! :wink:

version 2.5.3


P.
forum C++ in polish
cpp.g5.pl

Post Reply