android_python.txt              2024-08-22

scrcpy
======
1. Installing scrcpy on windows howto:
        https://www.smartprix.com/bytes/how-to-set-up-scrcpy-for-mirorring-phone-on-windows/
   this howto states:
    Enable Developer Options on your Android phone and turn on ‘USB Debugging’
    Now connect your phone to your PC via USB cable.
2. Samsung enable developer options:
    https://www.samsung.com/uk/support/mobile-devices/how-do-i-turn-on-the-developer-options-menu-on-my-samsung-galaxy-device/
3. use powered USB adaptor


Install MariaDB - Android
=========================
1. Android connected to internet
2. from Play Store:
   install Termux from Fredrik Farnwall
3. Open Termux
   $ pkg upgrade
   $ termux-setup-storage | Enable Termux
  ($ pkg uninstall mariadb)
   $ pkg install mariadb


Start MariaDB server
====================
1. in Termux
   $ mariadbd-safe &
2. ...
3. ^c
  ($ mysqladmin status)
   $ mysqladmin -u root shutdown


Create MariaDB user
===================
1. in Termux
   slide left to right
   Start new session (+)
2. $ mysql -u root
3. [(none)]>  DROP USER IF EXISTS 'me';
   [(none)]>  CREATE USER 'me'@'%' IDENTIFIED BY 'pwd';
   [(none)]>  GRANT ALL PRIVILEGES ON *.* TO 'me'@'%' WITH GRANT OPTION;
   [(none)]>  FLUSH PRIVILEGES;

   [(none)]>  SHOW DATABASES;
   [(none)]>  EXIT


Network connection - Android
============================
1. AccessPoint mode:
   Settings | Connections | Mobile Hotspot
   On | Network name = xxxxx | Password = yyyyy


Install MariaDB - Windows
=========================
1. Optional:
      Search | Add or remove programs
      MariaDB | Uninstall
2. URL: https://mariadb.org/ | Download
   MariaDB  Server 11.5.3 | Windows | x86_64 | MSI Package | Download
   run msi | root password = masterkey
3. Search | Services
   double click: MariaDB | Startup type = Disabled | Stop | OK


Network connection - Windows
============================
1. Wifi Connect to xxxxx : yyyyy
2. Settings | network & internet | Ethernet | Wifi Network
       IPv4 address         -->  192.168.118.201  Windows IP
       IPv4 DNS servers     -->  192.168.118.181  Android IP


Create Database
===============
1. open NotePad for writing SQL script:
2.

DROP DATABASE IF EXISTS my_db;
CREATE DATABASE my_db;
USE my_db;
CREATE TABLE tbl1 (id INT, naam VARCHAR(40), plaats VARCHAR(40));
INSERT INTO  tbl1 (id, naam, plaats) VALUES (1, 'Jan', 'Baarn');
INSERT INTO  tbl1 VALUES (2, 'Piet', 'Bussum');

3. save as my.sql
4. open power shell
   PS: cd <directory of my.sql>
   PS: 'C:\Program Files\MariaDB 11.5\bin\mysql.exe' -h 192.168.118.181 -u me -ppwd
5. [(none)]>  SOURCE my.sql;
   [(my_db)]> SHOW DATABASES;
   [(my_db)]> SHOW TABLES;
   [(my_db)]> SELECT * FROM tbl1;


Windows Python application
==========================
1. Optional:
      PS: py --version
      PS: py -m venv c:/work/venv
      PS: C:/work/venv/Scripts/Activate.ps1
      (venv) pip install pymysql
2. open Visual Studio Code
   connect to (venv)
3. create script file:

import  os;     os.system('cls')
import  pymysql as db

conn_str = dict(host='192.168.118.181', user='me', password='pwd', database='my_db')

# table Query
def test():
    conn = db.connect(**conn_str)
    cur  = conn.cursor()
    cur.execute('SELECT * FROM tbl1')
    data = cur.fetchall()
    conn.close()
    for row in data:
        print(row)

test()

4. run script


DBeaver
=======
1. start dBeaver
   (delete possible old link to my_db)
2. Database | New Database Connection | MariaDB, Next
   Server = 192.168.118.181
   Database = my_db
   Username = me
   Password = pwd
   Finish
3. Double click my_db
   Databases | my_db | Tables
   Double click tbl1 | Data
