mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-01-04 12:40:29 +01:00
* Examples for extension
git-svn-id: trunk@40609 -
This commit is contained in:
parent
f5a1fce16f
commit
51995c5cac
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -7661,6 +7661,8 @@ packages/sndfile/src/sndfile.pp svneol=native#text/plain
|
||||
packages/sqlite/Makefile svneol=native#text/plain
|
||||
packages/sqlite/Makefile.fpc svneol=native#text/plain
|
||||
packages/sqlite/Makefile.fpc.fpcmake svneol=native#text/plain
|
||||
packages/sqlite/examples/myext.lpi svneol=native#text/plain
|
||||
packages/sqlite/examples/myext.pp svneol=native#text/plain
|
||||
packages/sqlite/fpmake.pp svneol=native#text/plain
|
||||
packages/sqlite/src/sqlite.pp svneol=native#text/plain
|
||||
packages/sqlite/src/sqlite3.inc svneol=native#text/plain
|
||||
|
||||
66
packages/sqlite/examples/myext.lpi
Normal file
66
packages/sqlite/examples/myext.lpi
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<SaveOnlyProjectUnits Value="True"/>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="myext"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes Count="1" Active="Default">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="0"/>
|
||||
</RunParams>
|
||||
<Units Count="1">
|
||||
<Unit0>
|
||||
<Filename Value="myext.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="myext"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<RelocatableUnit Value="True"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Options>
|
||||
<ExecutableType Value="Library"/>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
||||
49
packages/sqlite/examples/myext.pp
Normal file
49
packages/sqlite/examples/myext.pp
Normal file
@ -0,0 +1,49 @@
|
||||
library myext;
|
||||
|
||||
{$mode objfpc}{$h+}
|
||||
|
||||
uses
|
||||
sysutils,
|
||||
ctypes,
|
||||
sqlite3,
|
||||
sqlite3ext;
|
||||
|
||||
procedure mysum(ctx: psqlite3_context; n: cint; v: ppsqlite3_value); cdecl;
|
||||
var
|
||||
a, b, r: cint;
|
||||
begin
|
||||
a := sqlite3_value_int(v[0]);
|
||||
b := sqlite3_value_int(v[1]);
|
||||
r := a + b;
|
||||
sqlite3_result_int(ctx, r);
|
||||
end;
|
||||
|
||||
procedure myconcat(ctx: psqlite3_context; n: cint; v: ppsqlite3_value); cdecl;
|
||||
var
|
||||
a, b, r: ansistring;
|
||||
begin
|
||||
a := sqlite3_value_text(v[0]);
|
||||
b := sqlite3_value_text(v[1]);
|
||||
r := a + b;
|
||||
sqlite3_result_text(ctx, @r[1], length(r), nil);
|
||||
end;
|
||||
|
||||
function sqlite3_extension_init(db: Psqlite3; pzErrMsg: Ppcchar;
|
||||
const pApi: Psqlite3_api_routines): cint; cdecl; export;
|
||||
var
|
||||
rc: cint;
|
||||
begin
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
rc := sqlite3_create_function(db, 'mysum', 2, SQLITE_UTF8, nil,
|
||||
@mysum, nil, nil);
|
||||
if rc = SQLITE_OK then
|
||||
Result := sqlite3_create_function(db, 'myconcat', 2, SQLITE_UTF8, nil,
|
||||
@myconcat, nil, nil);
|
||||
Result := rc;
|
||||
end;
|
||||
|
||||
exports
|
||||
sqlite3_extension_init;
|
||||
|
||||
begin
|
||||
end.
|
||||
Loading…
Reference in New Issue
Block a user