From 4dc8f0ba4f47191fdaefad5c6d42b255d0bbc435 Mon Sep 17 00:00:00 2001 From: brunzelchen Date: Mon, 24 May 2010 13:37:22 +0000 Subject: branch to merge video preview in song menu git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2411 b956fd51-792f-4845-bead-9b4dfca2ff2c --- VideoPreview/src/lib/SQLite/example/Sunset.jpg | Bin 0 -> 71189 bytes VideoPreview/src/lib/SQLite/example/TestSqlite.dpr | 15 ++ VideoPreview/src/lib/SQLite/example/TestSqlite.res | Bin 0 -> 876 bytes .../src/lib/SQLite/example/uTestSqlite.dfm | 110 ++++++++++ .../src/lib/SQLite/example/uTestSqlite.pas | 233 +++++++++++++++++++++ 5 files changed, 358 insertions(+) create mode 100644 VideoPreview/src/lib/SQLite/example/Sunset.jpg create mode 100644 VideoPreview/src/lib/SQLite/example/TestSqlite.dpr create mode 100644 VideoPreview/src/lib/SQLite/example/TestSqlite.res create mode 100644 VideoPreview/src/lib/SQLite/example/uTestSqlite.dfm create mode 100644 VideoPreview/src/lib/SQLite/example/uTestSqlite.pas (limited to 'VideoPreview/src/lib/SQLite/example') diff --git a/VideoPreview/src/lib/SQLite/example/Sunset.jpg b/VideoPreview/src/lib/SQLite/example/Sunset.jpg new file mode 100644 index 00000000..860f6eec Binary files /dev/null and b/VideoPreview/src/lib/SQLite/example/Sunset.jpg differ diff --git a/VideoPreview/src/lib/SQLite/example/TestSqlite.dpr b/VideoPreview/src/lib/SQLite/example/TestSqlite.dpr new file mode 100644 index 00000000..596a3a04 --- /dev/null +++ b/VideoPreview/src/lib/SQLite/example/TestSqlite.dpr @@ -0,0 +1,15 @@ +program TestSqlite; + +uses + Forms, + uTestSqlite in 'uTestSqlite.pas' {Form1}, + SQLiteTable3 in 'SQLiteTable3.pas', + SQLite3 in 'SQLite3.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. diff --git a/VideoPreview/src/lib/SQLite/example/TestSqlite.res b/VideoPreview/src/lib/SQLite/example/TestSqlite.res new file mode 100644 index 00000000..4bdd5e2e Binary files /dev/null and b/VideoPreview/src/lib/SQLite/example/TestSqlite.res differ diff --git a/VideoPreview/src/lib/SQLite/example/uTestSqlite.dfm b/VideoPreview/src/lib/SQLite/example/uTestSqlite.dfm new file mode 100644 index 00000000..6b4a2aaf --- /dev/null +++ b/VideoPreview/src/lib/SQLite/example/uTestSqlite.dfm @@ -0,0 +1,110 @@ +object Form1: TForm1 + Left = 199 + Top = 280 + Width = 541 + Height = 308 + Caption = 'Test SQLite 3' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'MS Sans Serif' + Font.Style = [] + OldCreateOrder = False + PixelsPerInch = 96 + TextHeight = 13 + object Label1: TLabel + Left = 24 + Top = 104 + Width = 28 + Height = 13 + Caption = 'Notes' + end + object Label2: TLabel + Left = 24 + Top = 44 + Width = 28 + Height = 13 + Caption = 'Name' + end + object Label3: TLabel + Left = 24 + Top = 72 + Width = 40 + Height = 13 + Caption = 'Number:' + end + object Label4: TLabel + Left = 24 + Top = 12 + Width = 11 + Height = 13 + Caption = 'ID' + end + object Image1: TImage + Left = 272 + Top = 12 + Width = 241 + Height = 165 + Proportional = True + Stretch = True + end + object btnTest: TButton + Left = 24 + Top = 224 + Width = 161 + Height = 37 + Caption = 'Test SQLite 3' + TabOrder = 0 + OnClick = btnTestClick + end + object memNotes: TMemo + Left = 24 + Top = 124 + Width = 185 + Height = 89 + Lines.Strings = ( + '') + ScrollBars = ssVertical + TabOrder = 1 + end + object ebName: TEdit + Left = 72 + Top = 40 + Width = 173 + Height = 21 + TabOrder = 2 + end + object ebNumber: TEdit + Left = 72 + Top = 68 + Width = 173 + Height = 21 + TabOrder = 3 + end + object ebID: TEdit + Left = 72 + Top = 12 + Width = 173 + Height = 21 + TabOrder = 4 + end + object btnLoadImage: TButton + Left = 192 + Top = 224 + Width = 157 + Height = 37 + Caption = 'Load image' + TabOrder = 5 + OnClick = btnLoadImageClick + end + object btnDisplayImage: TButton + Left = 360 + Top = 224 + Width = 157 + Height = 37 + Caption = 'Display image' + TabOrder = 6 + OnClick = btnDisplayImageClick + end +end diff --git a/VideoPreview/src/lib/SQLite/example/uTestSqlite.pas b/VideoPreview/src/lib/SQLite/example/uTestSqlite.pas new file mode 100644 index 00000000..484be71c --- /dev/null +++ b/VideoPreview/src/lib/SQLite/example/uTestSqlite.pas @@ -0,0 +1,233 @@ +unit uTestSqlite; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Dialogs, StdCtrls,SQLiteTable3, ExtCtrls, jpeg; + +type + TForm1 = class(TForm) + btnTest: TButton; + memNotes: TMemo; + Label1: TLabel; + Label2: TLabel; + ebName: TEdit; + Label3: TLabel; + ebNumber: TEdit; + Label4: TLabel; + ebID: TEdit; + Image1: TImage; + btnLoadImage: TButton; + btnDisplayImage: TButton; + procedure btnTestClick(Sender: TObject); + procedure btnLoadImageClick(Sender: TObject); + procedure btnDisplayImageClick(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + Form1: TForm1; + +implementation + +{$R *.dfm} + +procedure TForm1.btnTestClick(Sender: TObject); +var +slDBpath: string; +sldb: TSQLiteDatabase; +sltb: TSQLIteTable; +sSQL: String; +Notes: String; + +begin + +slDBPath := ExtractFilepath(application.exename) ++ 'test.db'; + +sldb := TSQLiteDatabase.Create(slDBPath); +try + +if sldb.TableExists('testTable') then begin +sSQL := 'DROP TABLE testtable'; +sldb.execsql(sSQL); +end; + +sSQL := 'CREATE TABLE testtable ([ID] INTEGER PRIMARY KEY,[OtherID] INTEGER NULL,'; +sSQL := sSQL + '[Name] VARCHAR (255),[Number] FLOAT, [notes] BLOB, [picture] BLOB COLLATE NOCASE);'; + +sldb.execsql(sSQL); + +sldb.execsql('CREATE INDEX TestTableName ON [testtable]([Name]);'); + +//begin a transaction +sldb.BeginTransaction; + +sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Some Name",4,587.6594,"Here are some notes");'; +//do the insert +sldb.ExecSQL(sSQL); + +sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Another Name",12,4758.3265,"More notes");'; +//do the insert +sldb.ExecSQL(sSQL); + +//end the transaction +sldb.Commit; + +//query the data +sltb := slDb.GetTable('SELECT * FROM testtable'); +try + +if sltb.Count > 0 then +begin +//display first row + +ebName.Text := sltb.FieldAsString(sltb.FieldIndex['Name']); +ebID.Text := inttostr(sltb.FieldAsInteger(sltb.FieldIndex['ID'])); +ebNumber.Text := floattostr( sltb.FieldAsDouble(sltb.FieldIndex['Number'])); +Notes := sltb.FieldAsBlobText(sltb.FieldIndex['Notes']); +memNotes.Text := notes; + +end; + +finally +sltb.Free; +end; + +finally +sldb.Free; + +end; + +end; + +procedure TForm1.btnLoadImageClick(Sender: TObject); +var +slDBpath: string; +sldb: TSQLiteDatabase; +sltb: TSQLIteTable; +iID: integer; +fs: TFileStream; + +begin + +slDBPath := ExtractFilepath(application.exename) ++ 'test.db'; + +if not FileExists(slDBPath) then begin +MessageDLg('Test.db does not exist. Click Test Sqlite 3 to create it.',mtInformation,[mbOK],0); +exit; +end; + +sldb := TSQLiteDatabase.Create(slDBPath); +try + +//get an ID +//query the data +sltb := slDb.GetTable('SELECT ID FROM testtable'); +try + +if sltb.Count = 0 then begin +MessageDLg('There are no rows in the database. Click Test Sqlite 3 to insert a row.',mtInformation,[mbOK],0); +exit; +end; + +iID := sltb.FieldAsInteger(sltb.FieldIndex['ID']); + +finally +sltb.Free; +end; + +//load an image +fs := TFileStream.Create(ExtractFileDir(application.ExeName) + '\sunset.jpg',fmOpenRead); +try + +//insert the image into the db +sldb.UpdateBlob('UPDATE testtable set picture = ? WHERE ID = ' + inttostr(iID),fs); + +finally +fs.Free; +end; + +finally +sldb.Free; + +end; + +end; + +procedure TForm1.btnDisplayImageClick(Sender: TObject); +var +slDBpath: string; +sldb: TSQLiteDatabase; +sltb: TSQLIteTable; +iID: integer; +ms: TMemoryStream; +pic: TJPegImage; + +begin + +slDBPath := ExtractFilepath(application.exename) ++ 'test.db'; + +if not FileExists(slDBPath) then begin +MessageDLg('Test.db does not exist. Click Test Sqlite 3 to create it, then Load image to load an image.',mtInformation,[mbOK],0); +exit; +end; + +sldb := TSQLiteDatabase.Create(slDBPath); +try + +//get an ID +//query the data +sltb := slDb.GetTable('SELECT ID FROM testtable'); +try + +if not sltb.Count = 0 then begin +MessageDLg('No rows in the test database. Click Test Sqlite 3 to insert a row, then Load image to load an image.',mtInformation,[mbOK],0); +exit; +end; + +iID := sltb.FieldAsInteger(sltb.FieldIndex['ID']); + +finally +sltb.Free; +end; + +sltb := sldb.GetTable('SELECT picture FROM testtable where ID = ' + inttostr(iID)); +try + +ms := sltb.FieldAsBlob(sltb.FieldIndex['picture']); +//note that the memory stream is freed when the TSqliteTable is destroyed. + +if (ms = nil) then begin +MessageDLg('No image in the test database. Click Load image to load an image.',mtInformation,[mbOK],0); +exit; +end; + +ms.Position := 0; + +pic := TJPEGImage.Create; +pic.LoadFromStream(ms); + +self.Image1.Picture.Graphic := pic; + +pic.Free; + +finally +sltb.Free; +end; + +finally +sldb.Free; + +end; + + +end; + +end. -- cgit v1.2.3