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,

    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 = "";
    END
    IF kociol_k3 = 1 THEN
    	k_k3 = "K3";
    ELSE
    	k_k3 = "";
    END
    IF kociol_k4 = 1 THEN
    	k_k4 = "K4";
    ELSE
    	k_k4 = "";
    END
    IF kociol_k5 = 1 THEN
    	k_k5 = "K5";
    ELSE
    	k_k5 = "";
    END
    IF kociol_k6 = 1 THEN
    	k_k6 = "K6";
    ELSE
    	k_k6 = "";
    END
    IF kociol_go = 1 THEN
    	k_go = "GO";
    ELSE
    	k_go = "";	
    END	
    IF citect_inf = 1 THEN
    	c_ci = "CITECT";
    ELSE
    	c_ci = "";	
    END	
    IF kog_G1 = 1 THEN
    	sG1 = "G1";
    ELSE
    	sG1 = "";	
    END
    IF kog_G2 = 1 THEN
    	sG2 = "G2";
    ELSE
    	sG2 = "";	
    END	
    IF kog_G3 = 1 THEN
    	sG3 = "G3";
    ELSE
    	sG3 = "";	
    END	
    IF kog_G4 = 1 THEN
    	sG4 = "G4";
    ELSE
    	sG4 = "";	
    END
    
    IF sortSelect = 1 THEN
    sort = "1";
    ELSE
    sort = "0";
    END
    
    select_start=1;
    
    
    	!gdy zapytanie STRING ma wiecej niz 255 znaków, musimy skladac STRING z kilku czesci	
    	sAppend1 = "SELECT * FROM ZDARZENIA ";
    	
    	sAppend2 =" WHERE (Data BETWEEN '"+data1+" "+godzina1+":"+minuty1+":00' AND '"+data2+" "+godzina2+":"+minuty2+":00')";
    	sAppend3 =" AND ( GRUPA = '"+k_k1 +"' OR GRUPA = '"+k_k2+"' OR GRUPA = '"+k_k3+"' OR GRUPA = '"+k_k4+"' ";
    	sAppend4 =" OR GRUPA = '"+k_k5+"' OR GRUPA = '"+k_k6+"' OR GRUPA = '"+k_go+"' OR GRUPA = '"+c_ci+"' ";
    	sAppend5 =" OR GRUPA = '"+sG1+"' OR GRUPA = '"+sG2+"' OR GRUPA = '"+sG3+"' OR GRUPA = '"+sG4+"')";
    	sAppend6 =" ORDER BY Data DESC ";
    
    
    	
    	!zm pomocnicze do wyświetlenia zapytania															
    	Query1 = sAppend1 + sAppend2 + sAppend3 + sAppend4;
    	Query2 = sAppend5 + sAppend6;
    	
    	hSQL9 = SQLCreate("DSN=SQLServer; Uid=sa; pwd=sapass;");
    	
    	IF hSQL9 <> -1 THEN
    		Status9 = SQLOpen(hSQL9);
    		IF Status9 = 0 THEN
    			SQLBeginTran(hSQL9);
    			SQLSet(hSQL9, 	sAppend1);
    			SQLAppend(hSQL9, sAppend2);
    			SQLAppend(hSQL9, sAppend3);
    			SQLAppend(hSQL9, sAppend4);
    			SQLAppend(hSQL9, sAppend5);
    			SQLAppend(hSQL9, sAppend6);
    			
    !			SQLAppend(hSQL, " ");
    				
    			hRec9 = SQLCall(hSQL9, "");
    			
    !++++++++++!potwierdzenie złozonego zapytania
    			SQLCommit(hSQL9);
    !diagnostyka błędów SQL			
    			IF hRec9 = -1 THEN
    				SQL_Licznik1 = SQL_Licznik1+1; !Licznik SQL Call, gdy nie wykona się INSERT do bazy
    				!Message("Information", SQLErrMsg(), 48);
    			END
    			SQLClose(hSQL9);
    		ELSE
    		SQL_Licznik2 = SQL_Licznik2+1; !Licznik SQL Open, gdy nie otworzy połączenia do bazy
    		Message("Information", SQLErrMsg(), 48);
    		END
    		SQLDispose(hSQL9);
    	ELSE
    	SQL_Licznik3 = SQL_Licznik3+1; !Licznik SQL Create, gdy nie stworzy połączenia do bazy (ODBC)
    	Message("Information", SQLErrMsg(), 48);
    	END
    	
    		Sleep(1);
    	select_start=0;
    
    filtrSQL = Query1 + Query2;
    
    event_query = filtrSQL;
    
    END

    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.

    	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

  • In your code you break up the query because of the string character limit, but at the end you merge all the parts together into 'fltrSQL', which is probably a tag. This combined string is then again too long and will be truncated.

    Things I can think of to make it fit are:
    - Use a shorter query: In SQL Server create a view of your table with very short column names (a single character if possible) and use that view in your query. Also, in your query, leave out as many spaces as you can (for example GRUPA = 'x' becomes GRUPA='x').
    - In SQL server create a stored procedure that performs the query, and use this as the Command Type in the Database Exchange control. See the Database Exchange Help file for examples of using stored procedures and its parameters.
    - Use a different database grid, like the SQL Table control from the Library Controls include project.

  • I used a stored procedure in MSSQL and my query is much shorter than 255. Thanks Patrick for advice.

Reply Children
No Data