Open and Save to MySQL Topic is solved

How-to's and other software related queries

Moderator: abstr

Post Reply
davidjimenez75
Posts: 16
Joined: Mon Nov 25, 2019 3:05 pm

Open and Save to MySQL

Post by davidjimenez75 » Fri Oct 04, 2024 6:01 pm

How can I test the Open/Save to MySQL?

For create a local MySQL (in XAMPP for Example)

- SERVER=127.0.0.1
- DATABASE=todolist
- USER=todolist
- PASS=todolist

Create the database:

Code: Select all

CREATE DATABASE IF NOT EXISTS todolist CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'todolist'@'%' IDENTIFIED BY 'todolist';
GRANT ALL PRIVILEGES ON `todolist`.* TO 'todolist'@'%';
FLUSH privileges;
What fields do I need?

Code: Select all

CREATE TABLE `todolist` (
  `idtask` bigint(20) NOT NULL,
  `name` text NOT NULL,
  `xml` text NOT NULL,
  `comments` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I was unable to use de ID field :?

User avatar
abstr
Site Admin
Posts: 370
Joined: Sun Jul 28, 2019 12:22 pm

Re: Open and Save to MySQL

Post by abstr » Sat Oct 05, 2024 2:42 am

Hi David

I am a total noob when it comes to databases (I can't even really write SQL), so I have implemented this plugin in the simplest terms I could imagine, saving each tasklist as a blob of XML.
mysqlsetup.png
mysqlsetup.png (7.85 KiB) Viewed 357 times
Here's the exported schema:

Code: Select all

-- MySQL dump 10.13  Distrib 8.0.36, for Win64 (x86_64)
--
-- Host: 127.0.0.1    Database: tasklists
-- ------------------------------------------------------
-- Server version	8.4.0

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `tasklists`
--

DROP TABLE IF EXISTS `tasklists`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tasklists` (
  `Id` int unsigned NOT NULL AUTO_INCREMENT,
  `Name` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `Xml` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Id_UNIQUE` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2024-10-05 19:35:06
I hope this is sufficient.

davidjimenez75
Posts: 16
Joined: Mon Nov 25, 2019 3:05 pm

Re: Open and Save to MySQL

Post by davidjimenez75 » Sun Oct 06, 2024 7:46 am

Is a great first step to test the speed of storing Big TaskLists on MySQL and being able to interact with other systems, event AI (ChatGPT API, Claude API, Ollama on Localhost, etc...)

Working OK, thank you! ;)

Create the dabase:

Code: Select all

CREATE DATABASE IF NOT EXISTS todolist CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'todolist'@'%' IDENTIFIED BY 'todolist';
GRANT ALL PRIVILEGES ON `todolist`.* TO 'todolist'@'%';
FLUSH privileges;
Create the table:

Code: Select all

CREATE TABLE `tasklists` (
  `Id` int unsigned NOT NULL AUTO_INCREMENT,
  `Name` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `Xml` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Id_UNIQUE` (`Id`));

User avatar
abstr
Site Admin
Posts: 370
Joined: Sun Jul 28, 2019 12:22 pm

Re: Open and Save to MySQL

Post by abstr » Sun Oct 06, 2024 8:04 am

This is the end result of many years thinking about how to implement a db backend.

Initially I wanted to implement it at a task level but I could never figure out how to implement self-referencing tables (for tasks within tasks).

This may no longer be much of an issue now that XML blobs can be queried directly in SQL (this is how I implemented the 'size' and 'last modified' columns in the dialog for selecting a tasklist).

Thx for your feedback.

davidjimenez75
Posts: 16
Joined: Mon Nov 25, 2019 3:05 pm

Re: Open and Save to MySQL

Post by davidjimenez75 » Sun Oct 06, 2024 8:12 am

Talk with Claude.ai about that ;)

This is what Claude think about de MySQL Structure

Code: Select all

-- Create the database
CREATE DATABASE IF NOT EXISTS todolist CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create the user and grant privileges
CREATE USER 'todolist'@'%' IDENTIFIED BY 'todolist';
GRANT ALL PRIVILEGES ON `todolist`.* TO 'todolist'@'%';
FLUSH PRIVILEGES;

-- Switch to the todolist database
USE todolist;

-- Table for tasks
CREATE TABLE tasks (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    status VARCHAR(50),
    priority INT,
    percentdone INT,
    startdate DATE,
    duedate DATE,
    creationdate DATETIME,
    lastmod DATETIME,
    comments TEXT,
    timeestimate FLOAT,
    timeestimateunits VARCHAR(10),
    timespent FLOAT,
    timespentunits VARCHAR(10)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Table for categories
CREATE TABLE categories (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) UNIQUE NOT NULL
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Junction table for task-category relationship (many-to-many)
CREATE TABLE task_categories (
    task_id INT,
    category_id INT,
    PRIMARY KEY (task_id, category_id),
    FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
    FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Table for custom attributes
CREATE TABLE custom_attributes (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) UNIQUE NOT NULL,
    attribute_type VARCHAR(50)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Table for custom attribute values
CREATE TABLE task_custom_attributes (
    task_id INT,
    attribute_id INT,
    value TEXT,
    PRIMARY KEY (task_id, attribute_id),
    FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
    FOREIGN KEY (attribute_id) REFERENCES custom_attributes(id) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Table for tags
CREATE TABLE tags (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) UNIQUE NOT NULL
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Junction table for task-tag relationship (many-to-many)
CREATE TABLE task_tags (
    task_id INT,
    tag_id INT,
    PRIMARY KEY (task_id, tag_id),
    FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
    FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

User avatar
abstr
Site Admin
Posts: 370
Joined: Sun Jul 28, 2019 12:22 pm

Re: Open and Save to MySQL

Post by abstr » Sun Oct 06, 2024 8:49 am

davidjimenez75 wrote:
Sun Oct 06, 2024 8:12 am
Talk with Claude.ai about that ;)
I would never have thought of that! I'm old-school!

The biggest problem I had was understanding how are Parent/Child tasks relationships would be handled, and how I would query the tables to reconstruct the XML required by the app...

And with all those tables (1 is enough for me!) there is so much more opportunity for bugs, so unless there is a really compelling use-case I think saving it as a text-blob is the limit of my skills!

JuandeArriba
MVP
MVP
Posts: 63
Joined: Mon Jul 29, 2019 5:25 am

Re: Open and Save to MySQL

Post by JuandeArriba » Mon Oct 07, 2024 11:05 am

+1
Discipline is your best friend

User avatar
abstr
Site Admin
Posts: 370
Joined: Sun Jul 28, 2019 12:22 pm

Re: Open and Save to MySQL

Post by abstr » Sun Oct 13, 2024 2:37 am

Hi @davidjimenez75

It occurs to me that it's a current weakness of this option that the user has to create the database before it can be used (as you discovered).

I'll see if it's feasible for me to provide that functionality myself.

Post Reply