How to pass to recordsource properties in database exchange control string more than 255 character ?

I use SQLAppend function to doing very long query for example
"SELECT * FROM TABLE WHERE Data Between BEGIN_date AND END_date AND (Grp='K1' OR Grp='K2' OR Grp='K3' OR Grp='K4' OR Grp='K5' OR Grp='K6' OR Grp='K7' OR Grp='K8' OR Grp='K9' OR Grp='K10') ORDER By Data DESC (K1-K10 are pushbuttons state), but string end at 255 characters and my Query stop work.

Parents
  • Hello Sebastian. After you form the first part of the string you should use SQLSet(handle,string) to set the first part in the buffer. After you form the second part of the string than you should call SQLAppend(handle,string) and after that SQLCall(handle,"") to execute the query.

  • Yes I know and I use in my function SQLAppend to send Query above 255,

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    FUNCTION SQLAgenerujZdarzenia()
    STRING k_k1,k_k2,k_k3,k_k4,k_k5,k_k6,k_go,c_ci,k_ko;
    STRING sG1 ,sG2, sG3, sG4;
    STRING sort;
    INT hSQL9; !uchwyt połączenia do bazy danych przez ODBC
    INT Status9; !status otwarcia połączenia do bazy danych
    INT hRec9; !status wywołania zapytania do bazy INSERT
    //zczytanie ustawień przycisków ze strony Zdarzen
    IF kociol_k1 = 1 THEN
    k_k1 = "K1";
    ELSE
    k_k1 = "";
    END
    IF kociol_k2 = 1 THEN
    k_k2 = "K2";
    ELSE
    k_k2 = "";
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    but the question is how to display in database exchange this query.

  • Hello Sebastian. First you have to close the connection before SQLDispose(). This is information from the manual (If there is an active SQL connection to a database, the SQL connection has to be closed before disposal.) In your code I see that there is possibility of disposing without closing the connection. Second SQLBeginTrans() according to the manual again it is not supported by all kind of databases (The SQLBeginTran() function is not supported by all databases). My suggestion is to remove SQLBeginTrans() and SQLCommint() and check if it will work.

    Here is an example from code which works fine. The database is MS Access.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    IF hSQL <> -1 THEN
    sName = "INSERT INTO MH VALUES (" + sDate + "," + IntToStr(TimeCurrent()) + "," + IntToStr(P3_PA0501_MH) + "," + IntToStr(P3_PA0502_MH) + "," + IntToStr(P3_PA0503_MH) + ",";
    sName = sName + IntToStr(P3_PA0504_MH) + "," + IntToStr(P1_B0301_MH) + "," + IntToStr(P1_B0302_MH) + "," + IntToStr(P1_B0303_MH) + "," + IntToStr(P1_PA0301_MH) + ",";
    sName = sName + IntToStr(P1_PA0302_MH) + "," + IntToStr(P1_PA0303_MH) + "," + IntToStr(P1_PA0304_MH) + "," + IntToStr(P1_B1101_MH) + "," + IntToStr(P1_B1102_MH) + ",";
    sName = sName + IntToStr(P1_B1103_MH) + "," + IntToStr(P2_PA2101_MH) + "," + IntToStr(P2_PA2102_MH) + "," + IntToStr(P2_PA2103_MH) + "," + IntToStr(P1_M1101_MH) + ",";
    sName = sName + IntToStr(P1_M1102_MH) + "," + IntToStr(P1_M1103_MH) + "," + IntToStr(P1_M1104_MH) + "," + IntToStr(P1_PUMP1_FeOCl_MH) + "," + IntToStr(P1_PUMP2_FeOCl_MH) + ",";
    Status = SQLSet(hSQL,sName);
    sName = IntToStr(P3_PA2901_MH) + "," + IntToStr(P3_PA2902_MH) + "," + IntToStr(P2_1_PA2301_MH) + "," + IntToStr(P2_1_PA2302_MH) + "," + IntToStr(P2_PA2104_MH) + ",";
    sName = sName + IntToStr(P2_PA2105_MH) + "," + IntToStr(P3_M0901_MH) + "," + IntToStr(P3_M0902_MH) + "," + IntToStr(P3_M1001_MH) + "," + IntToStr(P3_M1002_MH) + ",";
    sName = sName + IntToStr(P3_PA1001_MH) + "," + IntToStr(P3_PA1002_MH) + "," + IntToStr(P2_B2101_MH) + "," + IntToStr(P2_B2102_MH) + "," + IntToStr(P2_1_A2601_M1_MH) + "," + IntToStr(P2_1_A2601_M2_MH) + ")";
    Status = SQLAppend(hSQL,sName);
    Status = SQLCall(hSQL,"");
    IF Status <> 1 THEN
    Message("Information","MH" + SQLErrMsg(), 48);
    END
    ELSE
    Message("Information","MH" + SQLErrMsg(), 48);
    END
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Reply
  • Hello Sebastian. First you have to close the connection before SQLDispose(). This is information from the manual (If there is an active SQL connection to a database, the SQL connection has to be closed before disposal.) In your code I see that there is possibility of disposing without closing the connection. Second SQLBeginTrans() according to the manual again it is not supported by all kind of databases (The SQLBeginTran() function is not supported by all databases). My suggestion is to remove SQLBeginTrans() and SQLCommint() and check if it will work.

    Here is an example from code which works fine. The database is MS Access.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    IF hSQL <> -1 THEN
    sName = "INSERT INTO MH VALUES (" + sDate + "," + IntToStr(TimeCurrent()) + "," + IntToStr(P3_PA0501_MH) + "," + IntToStr(P3_PA0502_MH) + "," + IntToStr(P3_PA0503_MH) + ",";
    sName = sName + IntToStr(P3_PA0504_MH) + "," + IntToStr(P1_B0301_MH) + "," + IntToStr(P1_B0302_MH) + "," + IntToStr(P1_B0303_MH) + "," + IntToStr(P1_PA0301_MH) + ",";
    sName = sName + IntToStr(P1_PA0302_MH) + "," + IntToStr(P1_PA0303_MH) + "," + IntToStr(P1_PA0304_MH) + "," + IntToStr(P1_B1101_MH) + "," + IntToStr(P1_B1102_MH) + ",";
    sName = sName + IntToStr(P1_B1103_MH) + "," + IntToStr(P2_PA2101_MH) + "," + IntToStr(P2_PA2102_MH) + "," + IntToStr(P2_PA2103_MH) + "," + IntToStr(P1_M1101_MH) + ",";
    sName = sName + IntToStr(P1_M1102_MH) + "," + IntToStr(P1_M1103_MH) + "," + IntToStr(P1_M1104_MH) + "," + IntToStr(P1_PUMP1_FeOCl_MH) + "," + IntToStr(P1_PUMP2_FeOCl_MH) + ",";
    Status = SQLSet(hSQL,sName);
    sName = IntToStr(P3_PA2901_MH) + "," + IntToStr(P3_PA2902_MH) + "," + IntToStr(P2_1_PA2301_MH) + "," + IntToStr(P2_1_PA2302_MH) + "," + IntToStr(P2_PA2104_MH) + ",";
    sName = sName + IntToStr(P2_PA2105_MH) + "," + IntToStr(P3_M0901_MH) + "," + IntToStr(P3_M0902_MH) + "," + IntToStr(P3_M1001_MH) + "," + IntToStr(P3_M1002_MH) + ",";
    sName = sName + IntToStr(P3_PA1001_MH) + "," + IntToStr(P3_PA1002_MH) + "," + IntToStr(P2_B2101_MH) + "," + IntToStr(P2_B2102_MH) + "," + IntToStr(P2_1_A2601_M1_MH) + "," + IntToStr(P2_1_A2601_M2_MH) + ")";
    Status = SQLAppend(hSQL,sName);
    Status = SQLCall(hSQL,"");
    IF Status <> 1 THEN
    Message("Information","MH" + SQLErrMsg(), 48);
    END
    ELSE
    Message("Information","MH" + SQLErrMsg(), 48);
    END
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Children
No Data