152 lines
3.7 KiB
Markdown
152 lines
3.7 KiB
Markdown
# Database Manager Kivy App
|
|
|
|
A simple Kivy application for managing a MariaDB database with two columns (id and mass) for the `offsystemsCounting` table.
|
|
|
|
## Features
|
|
|
|
- **Search**: Look up records by ID
|
|
- **Add/Update**: Add new records or update existing ones
|
|
- **Delete**: Remove records from the database
|
|
- **View All**: Display all records in the database
|
|
- **Auto-create**: Table is created automatically if it doesn't exist
|
|
|
|
## Prerequisites
|
|
|
|
### MariaDB Server Setup
|
|
|
|
1. **Install MariaDB server** (if not already installed):
|
|
```bash
|
|
sudo apt update
|
|
sudo apt install mariadb-server
|
|
```
|
|
|
|
2. **Start MariaDB service**:
|
|
```bash
|
|
sudo systemctl start mariadb
|
|
sudo systemctl enable mariadb
|
|
```
|
|
|
|
3. **Secure MariaDB installation**:
|
|
```bash
|
|
sudo mysql_secure_installation
|
|
```
|
|
|
|
4. **Create the database and user**:
|
|
```bash
|
|
sudo mysql -u root -p
|
|
```
|
|
|
|
Then run these SQL commands:
|
|
```sql
|
|
CREATE DATABASE cantare_injectie;
|
|
CREATE USER 'omron'@'localhost' IDENTIFIED BY 'Initial01!';
|
|
GRANT ALL PRIVILEGES ON cantare_injectie.* TO 'omron'@'localhost';
|
|
FLUSH PRIVILEGES;
|
|
EXIT;
|
|
```
|
|
|
|
5. **Test the connection**:
|
|
```bash
|
|
mysql -u omron -p cantare_injectie
|
|
```
|
|
Enter password: `Initial01!`
|
|
|
|
## Installation
|
|
|
|
1. Install Python 3.7+ if not already installed
|
|
2. Install the required dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
Or using virtual environment:
|
|
```bash
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Usage
|
|
|
|
1. **Make sure MariaDB server is running**:
|
|
```bash
|
|
sudo systemctl status mariadb
|
|
```
|
|
|
|
2. **Run the application**:
|
|
```bash
|
|
python main.py
|
|
```
|
|
Or:
|
|
```bash
|
|
chmod +x run_app.sh
|
|
./run_app.sh
|
|
```
|
|
|
|
3. **To search for a record:**
|
|
- Enter an ID in the "ID" field (max 20 characters)
|
|
- Click "Search"
|
|
- If found, the mass will be displayed in the "Mass" field
|
|
|
|
4. **To add or update a record:**
|
|
- Enter both ID and mass value
|
|
- Click "Add/Update"
|
|
- If the ID exists, it will be updated; otherwise, a new record will be created
|
|
|
|
5. **To delete a record:**
|
|
- Enter the ID to delete
|
|
- Click "Delete"
|
|
- Confirm the deletion in the popup
|
|
|
|
6. **To refresh the display:**
|
|
- Click "Refresh All" to reload all data from the database
|
|
|
|
## Database Structure
|
|
|
|
The app connects to MariaDB database `cantare_injectie` with the following table structure:
|
|
|
|
```sql
|
|
CREATE TABLE offsystemsCounting (
|
|
id VARCHAR(20) PRIMARY KEY,
|
|
mass REAL NOT NULL
|
|
)
|
|
```
|
|
|
|
## Files
|
|
|
|
- `main.py`: Main Kivy application
|
|
- `database_manager.py`: MariaDB database operations class
|
|
- `requirements.txt`: Python dependencies
|
|
- `test_database.py`: Test script for database operations
|
|
- `run_app.sh`: Startup script
|
|
- `README.md`: This documentation
|
|
|
|
## Connection Settings
|
|
|
|
The application connects to MariaDB with these settings:
|
|
- **Host**: localhost
|
|
- **Database**: cantare_injectie
|
|
- **User**: omron
|
|
- **Password**: Initial01!
|
|
- **Table**: offsystemsCounting
|
|
|
|
## Troubleshooting
|
|
|
|
1. **Connection Error 1698**:
|
|
- Make sure MariaDB is running: `sudo systemctl start mariadb`
|
|
- Verify user exists and has correct password
|
|
- Check database exists: `SHOW DATABASES;`
|
|
|
|
2. **Access Denied**:
|
|
- Verify user permissions: `SHOW GRANTS FOR 'omron'@'localhost';`
|
|
- Reset password if needed: `ALTER USER 'omron'@'localhost' IDENTIFIED BY 'Initial01!';`
|
|
|
|
3. **Database/Table doesn't exist**:
|
|
- The application will create the table automatically
|
|
- Make sure the database `cantare_injectie` exists
|
|
|
|
## Notes
|
|
|
|
- IDs must be unique and max 20 characters
|
|
- Mass values must be valid decimal numbers
|
|
- The app includes comprehensive error handling and user feedback
|
|
- All database operations use parameterized queries for security |