diff --git a/SQL.md b/SQL.md index 33ac0ef..28e4760 100644 --- a/SQL.md +++ b/SQL.md @@ -585,6 +585,26 @@ To extract data from a database table, use the SELECT statement with the FROM cl SELECT column1, column2, column3 FROM table_name +##################################################### + + +## Mathematical Columns + + + +### Verfügbare Tabellen und Spalten: + +products: id, price, quantity +Erstellen Sie eine Abfrage, die Folgendes berechnet: + +1. Eine Spalte namens total_value, die den Preis mit der Menge multipliziert und eine feste Versandpauschale von 15 hinzufügt +2. Eine Spalte namens discounted_value, die: + - Zuerst den Preis mit der Menge multipliziert + - Dann einen 20%-Rabatt anwendet (multipliziert mit 0.8) + - Schließlich eine feste Versandpauschale von 10 hinzufügt + +Versuchen Sie, Klammern angemessen zu verwenden, um sicherzustellen, dass die Berechnungen in der richtigen Reihenfolge durchgeführt werden! + ##################################################### diff --git a/bruno-idoit-session.md b/bruno-idoit-session.md new file mode 100644 index 0000000..7ab51a5 --- /dev/null +++ b/bruno-idoit-session.md @@ -0,0 +1,85 @@ +# Bruno: Session zur i-doit aufbauen + +In Bruno bekommst du eine "Session" über eine Kombination aus **Environment-Variablen** und dem **API-Key-Login von i-doit**. i-doit selbst nutzt keine klassischen Cookie-Sessions für die JSON-RPC-API, sondern authentifiziert jeden Request per Header – der "Session-Charakter" kommt also über gespeicherte Variablen, die alle Requests teilen. + +## 1. Environment anlegen + +Anlegen eines Environment `demo-idoit` mit: + +``` +base_url: https://demo.i-doit.com/src/jsonrpc.php +apikey: c1ia5q +username: admin +password: admin +``` + +![](idoit01.png) + +![](idoit02.png) + + +## 2. Login-Request (holt die Session-ID) + +i-doit unterstützt eine echte Session über `idoit.login`. Der Response liefert einen `X-RPC-Auth-Session`-Header, den du für Folge-Requests wiederverwendest. + +**POST** `{{base_url}}` + +Headers: + +``` +Content-Type: application/json +X-RPC-Auth-Username: {{username}} +X-RPC-Auth-Password: {{password}} +``` + +![](idoit03.png) + + +Body (JSON): + +```json +{ + "version": "2.0", + "method": "idoit.login", + "params": { "apikey": "{{apikey}}" }, + "id": 1 +} +``` + +Im **Script → Post Response** die Session-ID in eine Variable schreiben: + +```javascript +bru.setEnvVar("session_id", res.getHeader("x-rpc-auth-session")); +``` + +## 3. Folge-Requests mit der Session + +Alle weiteren Requests nutzen dann statt Username/Passwort nur noch: + +``` +Content-Type: application/json +X-RPC-Auth-Session: {{session_id}} +``` + +Body z. B. für eine Objektabfrage: + +```json +{ + "version": "2.0", + "method": "cmdb.objects.read", + "params": { "apikey": "{{apikey}}", "filter": { "type": 5 } }, + "id": 1 +} +``` + +## 4. Logout (optional) + +```json +{ "version": "2.0", "method": "idoit.logout", "params": { "apikey": "{{apikey}}" }, "id": 1 } +``` + +mit Header `X-RPC-Auth-Session: {{session_id}}`. + +--- + +**Kernpunkt:** Die Session-ID aus dem Login-Response wird per Post-Response-Script als Environment-Variable gespeichert und von allen Requests im selben Environment geteilt. Damit sparst du dir den Login-Roundtrip pro Abfrage und hast quasi eine durchgehende Session. diff --git a/idoit-demo.zip b/idoit-demo.zip new file mode 100644 index 0000000..fd9836d Binary files /dev/null and b/idoit-demo.zip differ diff --git a/idoit01.png b/idoit01.png new file mode 100644 index 0000000..6f2e216 Binary files /dev/null and b/idoit01.png differ diff --git a/idoit02.png b/idoit02.png new file mode 100644 index 0000000..9491719 Binary files /dev/null and b/idoit02.png differ diff --git a/idoit03.png b/idoit03.png new file mode 100644 index 0000000..8ef75dd Binary files /dev/null and b/idoit03.png differ diff --git a/idoit04.png b/idoit04.png new file mode 100644 index 0000000..6f5b5a9 Binary files /dev/null and b/idoit04.png differ diff --git a/idoit05.png b/idoit05.png new file mode 100644 index 0000000..7ffc62e Binary files /dev/null and b/idoit05.png differ diff --git a/mysql_binary_search.md b/mysql_binary_search.md new file mode 100644 index 0000000..1ad8770 --- /dev/null +++ b/mysql_binary_search.md @@ -0,0 +1,160 @@ +# MySQL Binary Search – Fehlerhafte Zeile automatisch finden + +## Hintergrund + +Bei der Migration von Daten zwischen zwei Tabellen treten gelegentlich Fehler auf. Mit `LIMIT` und `OFFSET` lässt sich der fehlerhafte Bereich manuell eingrenzen – dieser Prozess kann jedoch durch einen Binary-Search-Ansatz vollständig automatisiert werden. + +--- + +## Einfaches Skript (SELECT *) + +Für ein simples `SELECT *` ohne komplexe Query: + +```bash +#!/bin/bash + +# Konfiguration +DB_USER="root" +DB_PASS="password" +DB_NAME="datenbank" + +SOURCE_TABLE="quelle" +TARGET_TABLE="ziel" + +# Gesamtanzahl Zeilen ermitteln +TOTAL=$(mysql -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" -sNe \ + "SELECT COUNT(*) FROM $SOURCE_TABLE;") + +echo "Gesamt Zeilen: $TOTAL" + +LOW=0 +HIGH=$TOTAL + +while [ $((HIGH - LOW)) -gt 1 ]; do + MID=$(( (LOW + HIGH) / 2 )) + FETCH=$((MID - LOW)) + + echo "Teste OFFSET=$LOW LIMIT=$FETCH ..." + + ERROR=$(mysql -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" 2>&1 < **Wichtig:** Ein `ORDER BY` ist zwingend erforderlich, damit die Zeilenreihenfolge zwischen den Aufrufen deterministisch bleibt. + +```bash +#!/bin/bash + +# Konfiguration +DB_USER="root" +DB_PASS="password" +DB_NAME="datenbank" + +# Deine Source-Query OHNE LIMIT/OFFSET – als Subquery nutzbar +SOURCE_QUERY="SELECT a.id, MAX(b.wert), a.name + FROM quelle a + JOIN andere b ON a.id = b.ref_id + GROUP BY a.id, a.name + ORDER BY a.id" + +TARGET_TABLE="ziel" + +# Gesamtanzahl Zeilen der Query ermitteln +TOTAL=$(mysql -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" -sNe \ + "SELECT COUNT(*) FROM ($SOURCE_QUERY) AS _count_query;") + +echo "Gesamt Zeilen: $TOTAL" + +LOW=0 +HIGH=$TOTAL + +while [ $((HIGH - LOW)) -gt 1 ]; do + MID=$(( (LOW + HIGH) / 2 )) + FETCH=$((MID - LOW)) + + echo "Teste OFFSET=$LOW LIMIT=$FETCH ..." + + ERROR=$(mysql -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" 2>&1 < +``` + +Doppelte Anführungszeichen außen verwenden, damit die einfachen Anführungszeichen im PHP-Array (`$row['ls']`) nicht kollidieren. + +Weiterer Fehler im Original: doppeltes `` und fehlendes schließendes ``. + +**Korrekter Block:** +```html +
+ + + + + + + + + + + +
Ticket-Nr.
AuftraggeberBearbeiter
+
+``` + +--- + +## 2. Spaltenbreite in Tabellen + +### Option 1 – Inline Style +```html +Auftraggeber +``` + +### Option 2 – CSS-Klasse +```css +table th { width: 150px; } +table th:first-child { width: 100px; } +``` + +### Option 3 – ``-Element (zentral für jede Spalte) +```html + + + + + + + + ... +
+``` + +> **Wichtig:** `table-layout: fixed` ist erforderlich, damit die Breiten zuverlässig greifen. + +```css +table { + table-layout: fixed; + width: 100%; +} +``` + +--- + +## 3. Spaltenbreiten zentral für mehrere Tabellen + +Jeder Tabelle eine eigene Klasse geben: + +```html + +
+``` + +CSS in einer zentralen `.css`-Datei: + +```css +table { + table-layout: fixed; + width: 100%; +} + +.tabelle-ticket col:nth-child(1) { width: 150px; } +.tabelle-ticket col:nth-child(2) { width: 250px; } +.tabelle-ticket col:nth-child(3) { width: 150px; } +.tabelle-ticket col:nth-child(4) { width: 250px; } + +.tabelle-adressen col:nth-child(1) { width: 100px; } +.tabelle-adressen col:nth-child(2) { width: 300px; } +``` + +Einbinden per: +```html + +``` + +--- + +## 4. Tabelle ignoriert Spaltenbreiten (Auto-Breite) + +**Ursache:** Fehlendes `table-layout: fixed`. + +```css +table { + width: 100%; + border-collapse: collapse; + table-layout: fixed; /* ← das fehlte */ +} +``` + +Außerdem: `max-width: auto` ist ungültig. Entweder weglassen oder konkreten Wert setzen: +```css +.content { + max-width: 1200px; /* oder weglassen */ +} +``` + +--- + +## 5. Input-Breite sprengt Tabellenlayout + +**Ursache:** `input { width: 100%; }` greift auch auf Inputs in Tabellenzellen. + +**Lösung:** Inputs in Tabellen explizit ausschließen: + +```css +/* Inputs nur im Formular-Bereich */ +.form-bereich input, +.form-bereich select { + width: 100%; + padding: 8px; + margin-top: 4px; +} + +/* Inputs in Tabellen zurücksetzen */ +td input, td select { + width: auto; + padding: 2px 4px; + margin-top: 0; +} +``` + +Oder Formular-Bereich per Klasse kapseln: + +```html +
+ + +
+ +
+ ... +
+```