Free Pascal with Terry

MySQL Access from Free Pascal Help Doc.

// The uses clause need this at a minnumum
Uses SysUtils, db, sqldb, mysql80conn;
// The NN can change as MySQL and MariaDB versions get updated.

These two files need included

{$I /home/terry/Documents/fpc/MysqlConnLib.inc}
// Must be where you put the file on your system
{$I /home/terry/Documents/fpc/DbConst.inc}
// Must be where you put the file on your system

In the Var section, variables of these types need declared:

MyConn:				TSqlConnector;
MyTran: 				TsqlTransaction;
MyQry:				TSqlQuery;

At the beginning of the program, these procedures/functions need called:

MyConn := CreateConnection('MySQL 8.0', '127.0.0.1', 'MyDatabase', MyUser, MyPass);
// MyUser, MyPass can be hard coded, but I like to hide those values
CreateTransaction(MyConn, MyTran);
MyQry := GetQuery(MyConn, MyTran);

// Doing a simple select

MyQry.SQL.Text := 'Valid Select Statement';
MyConn.Open;
MyQry.Open;
If MyConn.Connected Then
	Repeat
		Fld := MyQry.FieldByName('Col Name').AsString;
		Fld2 := := MyQry.FieldByName('PlanetName').AsFloat;
		WriteLn(Fld, Fld2);
		MyQry.Next;
	 Until MyQry.Eof;
MyQry.Close;
MyConn.Close;
MyQry.Free;
MyConn.Free;
MyTran.Free;

// Qry.First takes you to the First row, Qry.Last takes you to the last row.
// Qry.Prev backs you up one row

//To insert, Update or delete a row, format the query as needed and execute the following:

MyQry.Sql.Clear;
MyQry.Sql.Add(Sql);
MyQry.ExecSql;
MyTran.Commit;