print @@versionOutput:
Microsoft SQL Server 2014 (SP2-GDR) (KB4019093) - 12.0.5207.0 (X64) Jul 3 2017 02:25:44 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows NT 6.3(Build 9600: ) (Hypervisor)
Microsoft AX 2012, X++, C#, SQL server, SSRS, Java, JavaFX, Oracle, PL/SQL, Delphi - codes examples, step-by-step tutorials, experiences.
print @@versionOutput:
Microsoft SQL Server 2014 (SP2-GDR) (KB4019093) - 12.0.5207.0 (X64) Jul 3 2017 02:25:44 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows NT 6.3(Build 9600: ) (Hypervisor)
function GCD( _iNumber1, _iNumber2 : integer ) : integer;
var
iTemp : integer;
begin
if _iNumber1 < 0 then _iNumber1 := -_iNumber1;
if _iNumber2 < 0 then _iNumber2 := -_iNumber2;
repeat
if _iNumber1 < _iNumber2 then
begin
iTemp := _iNumber1;
_iNumber1 := _iNumber2;
_iNumber2 := iTemp;
end;
_iNumber1 := _iNumber1 mod _iNumber2;
until ( _iNumber1 = 0 );
result := _iNumber2;
end;
Calling: var
i : integer;
begin
i := GCD( 12, 16 );
ShowMessage( IntToStr( i ) );
end;
Output: var i, iK : integer; iX, iY, iGamma, iNumerator, iDenominator : double; pSerie : TLineSeries; pIntegral : TIntegral; begin Memo1.Clear; pSerie := TLineSeries( Chart1.Series[0] ); pSerie.Clear; pIntegral := TIntegral.Create; pIntegral.iStep := 0.05; pIntegral.SetInterval( 0.001, 20 ); { -- set param + calc GAMMA function } iK := 8; iGamma := GetGamma( iK/2 ); for i := 0 to pIntegral.pX.Count - 1 do begin iX := pIntegral.pX.GetValue( i ); try iNumerator := power( iX, iK/2-1 ) * exp( ( -1*iX ) /2 ); iDenominator := power( 2, iK / 2 ) * iGamma; if iDenominator <> 0 then iY := iNumerator / iDenominator else iY := 0; except iY := 0; end; pIntegral.pY.AddValue( iY ); { -- add to chart } pSerie.AddXY( iX, iY ); end; end;And here is very important Gamma() function with k parameter.
function GammaStirF( X : double ) : double; var y : double; w : double; v : double; stir : double; begin w := 1 / x; stir := 7.87311395793093628397E-4; stir := -2.29549961613378126380E-4 + w * stir; stir := -2.68132617805781232825E-3 + w * stir; stir := 3.47222221605458667310E-3 + w * stir; stir := 8.33333333333482257126E-2 + w * stir; w := 1 + w * stir; y := exp(x); if x > 143.01608 then begin v := power( x, 0.5 * x -0.25 ); y := v *( v / y ); end else begin y := power( x, x -0.5 ) / y; end; result := 2.50662827463100050242 * y * w; end; function GetGamma( _x : double ) : double; var p : double; PP : double; q : double; QQ : double; z : double; i : longint; SgnGam : double; begin SgnGam := 1; q := abs( _x ); if q > 33.0 then begin if _x < 0.0 then begin p := floor(q); i := round(p); if i mod 2 = 0 then begin SgnGam := -1; end; z := q - p; if z > 0.5 then begin p := p+1; z := q-p; end; z := q * sin( pi * z ); z := Abs(z); z := pi / ( z * GammaStirF( q ) ); end else begin z := GammaStirF( _x ); end; result := SgnGam * z; exit; end; z := 1; while _x >= 3 do begin _x := _x - 1; z := z *_x; end; while _x < 0 do begin if _x > -0.000000001 then begin result := z / ( ( 1 + 0.5772156649015329 *_x ) * _x ); exit; end; z := z /_x; _x := _x + 1; end; while _x < 2 do begin if _x < 0.000000001 then begin result := z / ( ( 1 + 0.5772156649015329 * _x ) *_x ); exit; end; z := z /_x; _x := _x + 1.0; end; if _x = 2 then begin result := z; exit; end; _x := _x - 2.0; PP := 1.60119522476751861407E-4; PP := 1.19135147006586384913E-3 + _X * PP; PP := 1.04213797561761569935E-2 + _X * PP; PP := 4.76367800457137231464E-2 + _X * PP; PP := 2.07448227648435975150E-1 + _X * PP; PP := 4.94214826801497100753E-1 + _X * PP; PP := 9.99999999999999996796E-1 + _X * PP; QQ := -2.31581873324120129819E-5; QQ := 5.39605580493303397842E-4 + _X * QQ; QQ := -4.45641913851797240494E-3 + _X * QQ; QQ := 1.18139785222060435552E-2 + _X * QQ; QQ := 3.58236398605498653373E-2 + _X * QQ; QQ := -2.34591795718243348568E-1 + _X * QQ; QQ := 7.14304917030273074085E-2 + _X * QQ; QQ := 1.00000000000000000320 + _X * QQ; result := z * PP / QQ; exit; end;Output:
![]() |
| k=2 |
![]() |
| k=8 |
connect sys/password as sysdba; alter user username account unlock;
var i : integer; iY : double; pDN : TDistribution_Normal; pSerie : TLineSeries; begin Memo1.Clear; /* prepare chart */ pSerie := TLineSeries( Chart1.Series[0] ); pSerie.Clear; /* prepare distribution data */ pDN := TDistribution_Normal.Create; pDN.Init( 0, 1 ); for i := 0 to pDN.pIntegral.pY.Count - 1 do begin { -- get value } iY := pDN.pIntegral.pY.GetValue( i ); pSerie.AddXY( i, iY ); end;And here is very important TDistribution_Normal.Init() function with parameters as MEAN and SIGMA, here is generated range MEAN +-3.5 SIGMA.
function TDistribution_Normal.Init( _iMean, _iSigma : double ) : boolean; var i : integer; iFrom, iTo, iValue : double; begin result := false; { -- check } if _iSigma <= 0 then begin ShowMessage( 'Distribution_Normal() - standard deviation can`t be 0.' ); exit; end; { -- add range -3.5 sigma - Mean - + 3.5 sigma } pIntegral.Clear; iFrom := _iMean - ( 3.5 * _iSigma ); iTo := _iMean + ( 3.5 * _iSigma ); { aproximation - 300 items } pIntegral.iStep := ( iTo - iFrom ) / 300; pIntegral.SetInterval( iFrom, iTo ); { -- calc values normal distribution for every X } for i := 0 to pIntegral.pX.Count - 1 do begin iValue := ( 1 / ( _iSigma * sqrt( 2*pi ) ) ) * exp( - ( sqr( pIntegral.pX.GetValue( i ) - _iMean ) ) / ( 2 * sqr( _iSigma ) ) ); pIntegral.pY.AddValue( iValue ); end; pIntegral.Calc; result := true; end;Output:
import javafx.scene.chart.PieChart; ... @FXML PieChart pieChart1; ... /* set text */ pieChart1.setTitle( "This is a chart" ); /* add data */ ObservableListOutput:series = FXCollections.observableArrayList(); series.add( new PieChart.Data( "Q1", 5 ) ); series.add( new PieChart.Data( "Q2", 5.5 ) ); series.add( new PieChart.Data( "Q3", 8 ) ); series.add( new PieChart.Data( "Q4", 3 ) ); pieChart1.setData( series );
import javafx.scene.chart.BarChart; ... @FXML BarChart barChart1; ... /* set texts */ barChart1.setTitle( "This is a chart" ); barChart1.getXAxis().setLabel( "x axis" ); barChart1.getYAxis().setLabel( "y axis" ); barChart1.setLegendVisible( false ); /* add data */ XYChart.Series series1 = new XYChart.Series(); series1.getData().add( new XYChart.Data( "Q1", 5 ) ); series1.getData().add( new XYChart.Data( "Q2", 5.5 ) ); series1.getData().add( new XYChart.Data( "Q3", 8 ) ); series1.getData().add( new XYChart.Data( "Q4", 3 ) ); barChart1.getData().add( series1 );Output:
uses IdHashMessageDigest;
...
var
sFile : string;
pSHA : TIdHashSHA1;
pStream : TFileStream;
begin
sFile := 'c:\_ax\error.png';
pSHA := TIdHashSHA1.Create;
pStream := TFileStream.Create( sFile, fmOpenRead or fmShareDenyWrite );
try
ShowMessage( 'File fingerprint = ' + pSHA.HashStreamAsHex( pStream ) );
finally
pStream.Free;
pSHA.Free;
end;
Output: public class FXMLMainController implements Initializable {
@FXML private Label lbl1;
@Override
public void initialize( URL url, ResourceBundle rb ) {
}
/* Method for label centering */
public void prepare() {
Scene scene = lbl1.getScene();
if ( scene != null ) {
lbl1.layoutXProperty().bind( scene.widthProperty().subtract(
lbl1.layoutBoundsProperty().get().getWidth()).divide( 2 ) );
lbl1.layoutYProperty().bind( scene.heightProperty().subtract(
lbl1.layoutBoundsProperty().get().getHeight()).divide( 2 ) );
}
}
}
Method prepare() must be called after creating Scene class instance:@Override
public void start(Stage stage) throws Exception {
FXMLLoader fLoader = new FXMLLoader( getClass().getResource( "FXMLMain.fxml" ) );
Parent root = fLoader.load();
FXMLMainController controller = fLoader.< fxmlmaincontroller >getController();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
/* needs to be called here */
controller.prepare();
}
Output: uses IdHashSHA;
...
var
pSHA : TIdHashSHA1;
begin
pSHA := TIdHashSHA1.Create;
try
ShowMessage( 'abc = ' + pSHA.HashStringAsHex( 'abc' ) + #13 +
'abc = ' + pSHA.HashStringAsHex( 'abc' ) + #13 +
'abd = ' + pSHA.HashStringAsHex( 'abd' ) );
finally
pSHA.Free;
end;
Output: uses IdHashMessageDigest;
...
var
pMD5: TIdHashMessageDigest5;
begin
pMD5 := TIdHashMessageDigest5.Create;
try
ShowMessage( 'abc = ' + pMD5.HashStringAsHex( 'abc' ) + #13 +
'abc = ' + pMD5.HashStringAsHex( 'abc' ) + #13 +
'abd = ' + pMD5.HashStringAsHex( 'abd' ) );
finally
pMD5.Free;
end;
Output: select a.* from ( select a.*, cast( cast( a.[free] as numeric(15,2) ) / cast( a.[space] as numeric(15,2) ) * 100 as numeric(15,2) ) as [free_%] from ( select a.numbersequence, a.lowest, a.highest, a.nextrec, a.highest - a.lowest as [space], a.highest - a.nextrec as [free] from numbersequencetable a where a.blocked = 0 and a.cyclic = 0 ) a ) a order by a.[free_%]Output:
numbersequence lowest highest nextrec space free free_%
-------------- ----------- ----------- ----------- ----------- ----------- --------
Inve_38 1 999999 703701 999998 296298 29.63
Inve_33 1 99999 31366 99998 68633 68.63
Gene_24 1 99999 29841 99998 70158 70.16
Time_6 1 9999999 2665830 9999998 7334169 73.34
Docu_3 1 99999 19037 99998 80962 80.96
Prod_26 1 9999999 1327561 9999998 8672438 86.72
Prod_27 14000 999999 130299 985999 869700 88.20
control userpasswords2Output:
use framework; exec sp_updatestats;Output:
Updating [dbo].[sql_detail_graphs]
[PK__sql_deta__3213E83F07EFD247] has been updated...
[_WA_Sys_00000002_00507F52] has been updated...
[_WA_Sys_0000000A_00507F52] has been updated...
[_WA_Sys_00000009_00507F52] has been updated...
[_WA_Sys_00000003_00507F52] has been updated...
5 index(es)/statistic(s) have been updated, 0 did not require update.
Updating [dbo].[sql_zal]
0 index(es)/statistic(s) have been updated, 0 did not require update.
...
Statistics for all tables have been updated.
ALTER trigger [dbo].[sql_insert] on [dbo].[sql] for insert as begin transaction; begin try /* -- add new initial role */ insert into [role_object] ( ident, [description], [role_object_type_ident] ) select inserted.id, null, 'Q' from inserted; /* -- add log row about creation to log table */ insert into sql_detail_changes ( sql_id, [description], [type] ) select inserted.id, 'Creation', 'I' from inserted; if @@TRANCOUNT > 0 commit transaction; end /* -- problem ? */ try begin catch if @@TRANCOUNT > 0 rollback transaction; end catch;
StringTokenizer pSpaceDelim = new StringTokenizer( "This is a text." );
System.out.println( "Count = " + pSpaceDelim.countTokens() + System.lineSeparator() );
while ( pSpaceDelim.hasMoreTokens() )
System.out.println( pSpaceDelim.nextToken() );
Output: Count = 4 This is a text.NOTE: System.lineSeparator() is system dependent line separator.
select count( * ) as rows from salesline a where a.itemid = 'PŘEPRAVNÉ' and a.confirmeddlv >= '2018/02/01' and a.confirmeddlv <= '2018/02/07'Output:
rows ----------- 0 (1 row(s) affected)..you get empty result set.
select count( * ) as rows
from salesline a
where
a.itemid collate latin1_general_ci_ai = 'PŘEPRAVNÉ' and
a.confirmeddlv >= '2018/02/01' and
a.confirmeddlv <= '2018/02/07'
Output: rows ----------- 4 (1 row(s) affected)..it is something else.
procedure TForm1.BIntegralClick(Sender: TObject);
var
i : integer;
iX, iY : double;
pIntegral : TIntegral;
pSerie : TLineSeries;
begin
pSerie := TLineSeries( Chart1.Series[0] );
pSerie.Clear;
{ -- prepare integral class - interval 0..PI }
pIntegral := TIntegral.Create;
pIntegral.SetInterval( 0, pi );
for i := 0 to pIntegral.pX.Count - 1 do
begin
{ calc Y value }
pIntegral.pY.AddValue( sqr( sin( pIntegral.pX.GetValue( i ) ) ) );
{ -> to graph }
iX := pIntegral.pX.GetValue( i );
iY := pIntegral.pY.GetValue( i );
pSerie.AddXY( iX, iY );
end;
ShowMessage( FloatToStr( pIntegral.Calc ) ); // 1.57
pIntegral.Free;
end;
Here is TIntegral.calc() method:{ --------------------------------------------------------------------------- Method computes integral value (trapezoidal rule). -------------------------------------------------------------------------- } function TIntegral.Calc( _iCheckSumIntegralValue : double = 999 ) : double; var i, iDeleteXFrom : integer; iValue : double; begin result := 0; { -- checks } if pX.Count < 2 then exit; if pX.Count <> pY.Count then exit; { -- delete values } pIntegral.Clear; pCumulation.Clear; { -- trapezoidal rule } iDeleteXFrom := -1; for i := 1 to pX.Count - 1 do begin { -- compute integral value in interval } iValue := ( ( pX.GetValueCheckNull( i ) - pX.GetValueCheckNull( i - 1 ) ) * ( ( pY.GetValueCheckNull( i ) + pY.GetValueCheckNull( i - 1 ) ) / 2 ) ); result := result + iValue; { -- check -> is greater than parameter ? } if _iCheckSumIntegralValue <> 999 then if result > _iCheckSumIntegralValue then begin { -- subtract } result := result - iValue; { -- index for removing } iDeleteXFrom := i; break; end; { -- record values } if bLogIntegral then pIntegral.AddValue( iValue ); if bLogCumulation then pCumulation.AddValue( result ); end; { -- delete items over test value (if exists) } if iDeleteXFrom <> -1 then for i := pX.Count - 1 downto iDeleteXFrom do begin pX.Delete( i ); pY.Delete( i ); end; end;Output:
String sText = ""; Integer iValue; String sValue = ""; /* -- convert from dec */ sValue = Integer.toString( 100, 10 ); sText += "dec(100) to dec =" + sValue + "\n"; sValue = Integer.toString( 100, 2 ); sText += "dec(100) to bin =" + sValue + "\n"; sValue = Integer.toString( 100, 16 ); sText += "dec(100) to hex =" + sValue + "\n"; sValue = Integer.toString( 255, 16 ); sText += "dec(255) to hex =" + sValue + "\n"; /* result */ memo.setText( sText );Output:
String sText = "";
Integer iValue;
String sValue = "";
/* -- convert to dec */
iValue = Integer.parseInt( "100", 10 );
sText += "dec(100) to dec = " + iValue.toString() + "\n";
iValue = Integer.parseInt( "100", 2 );
sText += "bin(100) to dec = " + iValue.toString() + "\n";
iValue = Integer.parseInt( "100", 16 );
sText += "hex(100) to dec = " + iValue.toString() + "\n";
iValue = Integer.parseInt( "ff", 16 );
sText += "hex(ff) to dec = " + iValue.toString() + "\n";
/* result */
memo.setText( sText );
Output: { --------------------------------------------------------------------------- Function calculate angle between points _iSource and _iDest in direction from _iSource. Returns value [0-360]. -------------------------------------------------------------------------- } function CalcAngle( _iSource, _iDest : TPoint ) : double; var iAngle : extended; begin iAngle := ArcTan2( _iSource.Y - _iDest.Y, _iSource.X - _iDest.X ); result := ( iAngle * 180 ) / pi; { greater than 180 is negative -> change it } if result < 0 then result := 180 + ( 180 + result ); end;And here is calling examle:
procedure TForm1.Button2Click(Sender: TObject); var pt1, pt2, pt3, pt4 : TPoint; iResult1, iResult2, iResult3 : double; begin pt1.x := 50; pt1.y := 50; pt2.x := 100; pt2.y := 100; pt3.x := 150; pt3.y := 50; pt4.x := 100; pt4.y := 150; iResult1 := CalcAngle( pt2, pt1 ); iResult2 := CalcAngle( pt2, pt3 ); iResult3 := CalcAngle( pt2, pt4 ); ShowMessage( iResult1.ToString() + ' , ' + iResult2.ToString() + ' , ' + iResult3.ToString ); end;Output:
var
pStoredProc : TStoredProc;
begin
try
pStoredProc := TStoredProc.Create( Application );
pStoredProc.DatabaseName := orcl.DataBaseName;
{ -- call stored procedure }
pStoredProc.StoredProcName := AnsiUpperCase( 'factory.an_p1.Sql_Standard_DeleteDay' );
pStoredProc.Prepare;
pStoredProc.Params.ParamByName( 'pPeriod' ).AsString := _sPeriod;
pStoredProc.ExecProc;
finally
pStoredProc.Free;
end;
var pItem : TListItem; begin ... Item := List.Items.Add; pItem.ImageIndex := -1; pItem.Caption := IntToStr( iCounter ); pItem.SubItems.Add( s.Name ); pItem.SubItems.Add( IntToStr( iRowCount ) ); pItem.SubItems.Add( IntToStr( iRowCountSum ) );Output:
var iRowCount : integer; F : TextFile; begin ... { read row count } try iRowCount := 0; AssignFile( F, EPath.Text + s.Name ); Reset( F ); while not EOF( F ) do begin readln( F, sText ); inc( iRowCount ); end; ... finally CloseFile( F ); end; ...
const giCount = 15;
giDetail = 10;
...
procedure TForm1.BSpline_Clamped;
var
j, i, iIndex : integer;
iNumSegmentsCount : integer;
iT, i1_T, iB0, iB1, iB2, iB3 : double;
iNewX, iNewY : double;
pSerieLine : TLineSeries;
iValue : extended;
begin
pSerieLine := TLineSeries( Chart1.Series[1] );
pSerieLine.Clear;
{ draw count of cubic curves }
for iIndex := -2 to px.Count - 2 do
begin
{ every curve generate from I parts }
for i := 0 to giDetail - 1 do
begin
iT := i / (giDetail-1);
i1_T := 1 - iT;
iB0 := ( i1_T * i1_T * i1_T ) / 6;
iB1 := ( ( 3 * iT * iT * iT ) - ( 6 * iT * iT ) + 4 ) / 6;
iB2 := ( ( -3 * iT * iT * iT ) + ( 3 * iT * iT ) + ( 3 * iT ) + 1 ) / 6;
iB3 := ( iT * iT * iT ) / 6;
iNewX := iB0 * GetValueX( iIndex ) +
iB1 * GetValueX( iIndex + 1 ) +
iB2 * GetValueX( iIndex + 2 ) +
iB3 * GetValueX( iIndex + 3 )
;
iNewY := iB0 * GetValueY( iIndex ) +
iB1 * GetValueY( iIndex + 1 ) +
iB2 * GetValueY( iIndex + 2 ) +
iB3 * GetValueY( iIndex + 3 );
pSerieLine.AddXY( iNewX, iNewY );
end;
end;
end;