Ok, this all works from Linux Mint running where I am running Mariadb 10.11.14. 
 I ahave also ran this on newer versions of mint w/o issues.  But on True Blue 
Debian systems I haven't gotten it to work.

Ok, yesterday I installed Devaun 6.12.86 on an old laptop (i5-2450m) and 
installed mariadb 11.8.6. According to the web that version is compatible with 
Mysql 8.0.  I created the database and table and added terry to the grant table.

I then did a fresh compile and tried running it:

fpc ImportCars.pas
Free Pascal Compiler version 3.2.2+dfsg-46 [2025/02/08] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling ImportCars.pas
Linking ImportCars
97 lines compiled, 0.3 sec

./ImportCars 
An unhandled exception occurred at $00000000004F54E9:
EInOutError: Can not load default MySQL library ("libmysqlclient.so.21" or 
"libmysqlclient.so"). Check your installation.
  $00000000004F54E9
  $0000000000482FE5
  $000000000047054D

I tried then to install libmysqlclient-dev but according to apt-get that has 
been discontinued and replaced with either libmariadb-dev or 
libmariadb-dev-compat.  I tried both with the following results:

sudo apt-get install libmariadb-dev
./ImportCars
An unhandled exception occurred at $00000000004F54E9:
EInOutError: Can not load default MySQL library ("libmysqlclient.so.21" or 
"libmysqlclient.so"). Check your installation.
  $00000000004F54E9
  $0000000000482FE5
  $000000000047054D

I then removed that library and installed the 2nd library.

sudo apt-get remove libmariadb-dev

sudo apt-get install libmariadb-dev-compat

./ImportCars 
An unhandled exception occurred at $0000000000483045:
EInOutError: TMySQL80Connection can not work with the installed MySQL client 
version: Expected (8.0), got (3.4.9).
  $0000000000483045
  $000000000047054D

The source code for ImportCars.pas is 

Program ImportTow;
Uses SysUtils, StrUtils, db, sqldb, mysql80conn;

{$I /home/terry/Documents/fpc/MysqlConnLib.inc}
{$I /home/terry/Documents/fpc/DbConst.inc}

Var
        CConn:                          TSqlConnector;
        CTran:                          TsqlTransaction;
        CQry:                                   TSqlQuery;
        IFile:                          Text;
        Make, Model, Engine, Buffer,
        Trans, Drive, CityStr, 
        HwyStr, Yr:                             String;
        Sql:                                    AnsiString;
        
Function Strip(s: String): String;
Var
        i:              LongInt;
Begin
        i := Pos(' ', s);
        s := Copy(s, i+1, Length(s));
        Strip := s;     
End;
        
        
Begin
        CConn := CreateConnection('MySQL 8.0', '127.0.0.1', 'TowDB', MyUser, 
MyPass);
        CreateTransaction(CConn, CTran);
        CQry := GetQuery(CConn, CTran);
        CConn.Open;
        Assign(IFile, 'cars.csv');
        Reset(IFile);
        ReadLn(IFile, Buffer);ReadLn(IFile, Buffer);
        Repeat
                Yr      := ExtractWord(16, Buffer, [',']);
                Yr      := Copy(Yr, 2, Length(Yr)-2);
                Make    := ExtractWord(14, Buffer, [',']);
                Make    := Copy(Make, 2, Length(Make)-2);
                Model   := ExtractWord(13, Buffer, [',']);
                Model   := Copy(Model, 2, Length(Model)-2);
                Model   := Strip(Model);
                Model   := Strip(Model);
                Engine  := ExtractWord(5, Buffer, [',']);
                Engine  := Copy(Engine, 2, Length(Engine)-2);
                Trans   := ExtractWord(12, Buffer, [',']);
                Trans   := Copy(Trans, 2, Length(Trans)-2);
                Drive   := ExtractWord(4, Buffer, [',']);
                Drive   := Copy(Drive, 2, Length(Drive)-2);
                CityStr := ExtractWord(9, Buffer, [',']);
                HwyStr  := ExtractWord(11, Buffer, [',']);
                
                Sql := 'Insert into CarsTable(Yr, Make, Model, Engine, Drive, 
Trans, City, Hwy) Values (' +
                        QuotedStr(Yr) + ', ' +                  
                        QuotedStr(Make) + ', ' +
                        QuotedStr(Model) + ', ' +
                        QuotedStr(Engine) + ', ' +
                        QuotedStr(Drive) + ', ' +
                        QuotedStr(Trans) + ', ' +
                        CityStr + ', ' +
                        HwyStr + ')';
                // WriteLn('Sql:   ', Sql);
                CQry.Sql.Clear;
                CQry.Sql.Add(Sql);
                CQry.ExecSql;
                CTran.Commit;
                ReadLn(IFile, Buffer);
        Until Eof(IFile);
End.

And /home/terry/Documents/fpc/MysqlConnLib.inc contains:

function GetQuery(Conn: TSqlConnector; Tran: TSqlTransaction) : TSQLQuery;
  var MyQuery : TSQLQuery;
begin
  MyQuery := TSQLQuery.Create(Tran);
  MyQuery.Database := Conn;
  MyQuery.Transaction := Tran;
  GetQuery := MyQuery;
end;

Procedure CreateTransaction(Conn: TSqlConnector;Var Tran: TSqlTransaction);
Begin
  Tran := TSQLTransaction.Create(Tran);
  Tran.Database := Conn;
End;
        
Function CreateConnection(CType, HostAddr, Database, User, Password: String): 
TSqlConnector;
Var
        Conn:   TSqlConnector;
Begin
        Conn := TSQLConnector.Create(nil);
        Conn.ConnectorType      := CType;
        Conn.Hostname   := HostAddr;
        Conn.DatabaseName       := Database;
        Conn.UserName           := User;
        Conn.Password           := Password;
        CreateConnection        := Conn; 
End;




-- 
Terry A. Haimann <[email protected]>
_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to