Sayfayı Yazdır | Pencereyi Kapat

SQLite'a Data Yazdıramıyorum

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=1040
Tarih: 25 Haziran 2025 Saat 07:02
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: SQLite'a Data Yazdıramıyorum
Mesajı Yazan: cerenn
Konu: SQLite'a Data Yazdıramıyorum
Mesaj Tarihi: 24 Haziran 2025 Saat 16:27
 var
  MyForm : TclForm;
  PListView1 : TClProListView;
  DesignerPanel1 : TClProListViewDesignerPanel;
  ad : TClProLabel;
  
  void SqLiteInsertData;
  {
    try
      Clomosy.DBSQLiteQuery.Sql.Text = '
    INSERT INTO Kategoriler (id, ad) VALUES (1, ''Yemek'');
    INSERT INTO Kategoriler (id, ad ) VALUES (2, ''Kıyafet'');';
    
      
      ShowMessage('Adding data to the table was successful!');
    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
 
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Kategoriler";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      // Check the results
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
      
      // Create the table if it does not exist
      if not (TableExists)
      {
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE Kategoriler (
        id INTEGER NOT NULL,
        ad TEXT NOT NULL,
        PRIMARY KEY (id)
       );';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
        
        ShowMessage('Table successfully added to the database!');
        SqLiteInsertData;
      } else
      {
        ShowMessage('The Products table already exists.');
      }

    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void GetData;
  var
    Qry : TClSQLiteQuery;
  {
    try
      Qry = Clomosy.DBSQLiteQueryWith('SELECT id as clRecord_GUID, ad from Kategoriler');
      Qry.OpenOrExecute;
      if (Qry.Found)
      {
        PListView1.clLoadProListViewDataFromDataset(Qry);
      }
      
    except
      ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
    } 
  }

 void CreateListView;
 {
   PListView1 = MyForm.AddNewProListView(MyForm,'PListView1');
   PListView1.Properties.ItemSpace = 10;
   PListView1.Align = AlClient;
   PListView1.Margins.Bottom = 20;
   PListView1.Margins.Top = 20;
   PListView1.Margins.Right = 20;
   PListView1.Margins.Left = 20;
   PListView1.clProSettings.ColCount = 2;
   PListView1.clProSettings.ItemHeight = 150;
   PListView1.clProSettings.ItemWidth = 150;
   PListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#F5BCC9');
   PListView1.clProSettings.BorderWidth = 2;
   PListView1.clProSettings.RoundWidth = 5;
   PListView1.clProSettings.RoundHeight = 5;
   PListView1.clProSettings.ViewType = lvIcon;
   PListView1.SetclProSettings(PListView1.clProSettings);
   PListView1.ListType = 'horizontal';
 }

  
    void CreateDesignerPanel;
 {
   DesignerPanel1 = MyForm.AddNewProListViewDesignerPanel(PListView1,'DesignerPanel1');
   DesignerPanel1.Height = 100;
   DesignerPanel1.Width = 150;
   DesignerPanel1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#F6EDDB');
   DesignerPanel1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#F5BCC9');
   DesignerPanel1.clProSettings.BorderWidth = 2;
   DesignerPanel1.clProSettings.RoundWidth = 20;
   DesignerPanel1.clProSettings.RoundHeight = 20;
   DesignerPanel1.SetclProSettings(DesignerPanel1.clProSettings);
   PListView1.SetDesignerPanel(DesignerPanel1);
 }
 void CreateProductNameAndPrice;
 {
   ad = MyForm.AddNewProLabel(DesignerPanel1,'ad','test');
   ad.Align = AlMostTop;
   ad.Height = 20;
   ad.Margins.Bottom = 10;
   ad.Margins.Top = 10;
   ad.Margins.Right = 10;
   ad.Margins.Left = 10;
   DesignerPanel1.AddPanelObject(ad,clCaption);
   ad.Properties.AutoSize = True;
   }


  {
    MyForm = TclForm.Create(Self);
    CreateListView;
    CreateDesignerPanel;
    SqLiteConnectionCreateTable;
    CreateProductNameAndPrice;
    GetData;
    
    MyForm.Run;
  }                                                                                                                              Merhaba, doküman sayfasında olan kodun yanlışlık yapmadıysam aynısını aldım.Tek fark tablomun adı ve içeriği.Data eklendi mesajını alıyorum ama table oluşturulsa dahi datalar ısrarla eklenmiyor.Sebebi nedir acaba?



Cevaplar:
Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 24 Haziran 2025 Saat 17:52

Merhaba Ceren,

Kodu incelediğimde herhangi bir hata görünmüyor. Bende sorunsuz şekilde çalıştı.

Proje klasöründeki mevcut .db dosyasını silip projeyi tekrar çalıştırmayı dener misin?




Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net