diff --git a/.gradle/7.5.1/checksums/checksums.lock b/.gradle/7.5.1/checksums/checksums.lock
new file mode 100644
index 0000000..ae40acf
Binary files /dev/null and b/.gradle/7.5.1/checksums/checksums.lock differ
diff --git a/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock
new file mode 100644
index 0000000..24ecbec
Binary files /dev/null and b/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock differ
diff --git a/.gradle/7.5.1/dependencies-accessors/gc.properties b/.gradle/7.5.1/dependencies-accessors/gc.properties
new file mode 100644
index 0000000..e69de29
diff --git a/.gradle/7.5.1/executionHistory/executionHistory.bin b/.gradle/7.5.1/executionHistory/executionHistory.bin
new file mode 100644
index 0000000..ca25bd8
Binary files /dev/null and b/.gradle/7.5.1/executionHistory/executionHistory.bin differ
diff --git a/.gradle/7.5.1/executionHistory/executionHistory.lock b/.gradle/7.5.1/executionHistory/executionHistory.lock
new file mode 100644
index 0000000..da33ec0
Binary files /dev/null and b/.gradle/7.5.1/executionHistory/executionHistory.lock differ
diff --git a/.gradle/7.5.1/fileChanges/last-build.bin b/.gradle/7.5.1/fileChanges/last-build.bin
new file mode 100644
index 0000000..f76dd23
Binary files /dev/null and b/.gradle/7.5.1/fileChanges/last-build.bin differ
diff --git a/.gradle/7.5.1/fileHashes/fileHashes.lock b/.gradle/7.5.1/fileHashes/fileHashes.lock
new file mode 100644
index 0000000..c3b7ecb
Binary files /dev/null and b/.gradle/7.5.1/fileHashes/fileHashes.lock differ
diff --git a/.gradle/7.5.1/gc.properties b/.gradle/7.5.1/gc.properties
new file mode 100644
index 0000000..e69de29
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
new file mode 100644
index 0000000..f3a69dd
Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties
new file mode 100644
index 0000000..15ac27a
--- /dev/null
+++ b/.gradle/buildOutputCleanup/cache.properties
@@ -0,0 +1,2 @@
+#Wed Jul 19 11:31:59 IRDT 2023
+gradle.version=7.5.1
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
new file mode 100644
index 0000000..c766773
Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ
diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe
new file mode 100644
index 0000000..f64cd3f
Binary files /dev/null and b/.gradle/file-system.probe differ
diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..6b3fb31
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+KirbyQL
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..611e7c8
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinScripting.xml b/.idea/kotlinScripting.xml
new file mode 100644
index 0000000..d3e67dd
--- /dev/null
+++ b/.idea/kotlinScripting.xml
@@ -0,0 +1,9 @@
+
+
+
+
+ 2147483647
+ true
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..fdf8d99
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 4108f4f..f08ef53 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,7 +8,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 62c6abb..3f5d830 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,19 +5,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -27,26 +84,105 @@
+
+
+
- {
+ "keyToString": {
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "last_opened_file_path": "C:/GitHub/SQLAPI",
+ "project.structure.last.edited": "Project",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2"
}
-}]]>
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 2db3a8a..b005ae3 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,13 @@
-# SQL API
-This project is made for people who are bored of using sql so they can now rest while using the library. Its lightweight and easy to use.
-Feel free to contribiute in the project and also feel free to modify the project but please do not reshare this project to somewhere without naming me(MmdGIO) as the project author.
+# KirbyQL
+
+KirbyQL is another light-weight orm which is really easier to use than other ones.
+The basic idea comes from those days that I had to face sql everytime I had a new project.
+So I decided to make a lightweight and also simple library to use on my projects.
## Installation
**Gradle**:
+
```gradle
allprojects {
repositories {
@@ -21,64 +24,103 @@ dependencies {
}
```
+
**Maven**
+
```xml
-
-
- jitpack.io
- https://jitpack.io
-
-
+
+
+
+ jitpack.io
+ https://jitpack.io
+
+
```
```xml
-
- com.github.GaMeIsNtOvEr
- SQLApi
- Tag
-
+
+
+ com.github.GaMeIsNtOvEr
+ SQLApi
+ Tag
+
```
+
## Getting Started
+
To get started you need to create an instance from the database.
-the Database class requires DatabaseInfo to get to know what type of database do we have and also some more details about how to connect to the database.
+the Database class requires DatabaseInfo to get to know what type of database do we have and also some more details
+about how to connect to the database.
+
```java
+import me.gameisntover.kirbyql.database.DatabaseInfo;
+
// Getting the mysql information to connect.
-Database mySqlInfo = new DatabaseInfo("database name","localhost",3306,"root","password");
-// Creates a instance of MySQL MariaDB is only supported for now.
-Database mySQL = new Database(mySqlInfo);
-
-// Getting the database file which we want it to be used for SQLite
-File myDBFile = new File("myDatabase.db");
-// Checking if file doesnt exists so we create a new file.
-if (!myDBFile.exists()) {
- try {
- myDBFile.createNewFile();
- } catch (IOException e){
- e.printStackTrace();
+public class KirbyTest {
+ public static void main(String[] args) {
+ DatabaseInfo mySqlInfo = new DatabaseInfo("database name", "localhost", 3306, "root", "password");
+ // Creates an instance of MySQL MariaDB is only supported for now.
+ Database mySQL = new Database(mySqlInfo);
+
+ // Getting the database file which we want it to be used for SQLite
+ File myDBFile = new File("myDatabase.db");
+ // Checking if file doesn't exist, so we create a new file.
+ if (!myDBFile.exists()) {
+ try {
+ myDBFile.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ DatabaseInfo sqlLiteInfo = new DatabaseInfo(myDBFile);
+ // Creates an instance of SQLite.
+ Database sqLite = new Database(new DatabaseInfo());
+
}
}
-DatabaseInfo sqlLiteInfo = new DatabaseInfo(myDBFile);
-// Creates an instance of SQLite.
-Database sqLite = new Database(new DatabaseInfo())
```
-With these above you've learned how to create a MySQL/SQLite database. but now lets see how to basically create new table/insert/update/select some data.
+
+With these above you've learned how to create a MySQL/SQLite database. but now lets see how to basically create new
+table/insert/update/select/delete some data.
+
```java
-Database database = new Database(new DatabaseInfo("database name","localhost",3306,"root","password"));
-//the third arguement is being used for if its primary key or not and the 4th one is for not updating the object on update function.
-DBObject name = DBObject.of("name","TEXT",false);
+import me.gameisntover.kirbyql.database.Database;
+import me.gameisntover.kirbyql.database.function.InsertDataFunction;
+import me.gameisntover.kirbyql.database.function.SelectFunction;
+import me.gameisntover.kirbyql.database.function.UpdateDataFunction;
+import me.gameisntover.kirbyql.database.table.SQLTable;
-DBObject id = DBObject.of("id","VARCHAR(36)",true,true);
-database.createNewTable("workers",name,id);
+import java.util.UUID;
+
+public class KirbyTest {
+ public static void main(String[] args) {
+ Database database = new Database(new DatabaseInfo("database name", "localhost", 3306, "root", "password"));
+//the third arguement is being used for if its primary key or not and the 4th one is for not updating the object on update function
+ InsertDataFunction fun =
+ DBObject < String > name = DBObject.of("name", "TEXT", false);
+
+ DBObject id = DBObject.of("id", "VARCHAR(36)", true, true);
+ SQLTable table = database.createNewTable("workers", name, id);
//if you're using an object which is not primitive don't forget to add toString() at the end of the object
+ InsertDataFunction insert = (InsertDataFunction) table.requestFunction(InsertDataFunction.class);
+ UUID uid = UUID.randomUUID();
+ insert.values(name.clone("Mmd"), uid.clone(id.toString())).execute();
+
-database.insertData("workers",name.clone("Mmd"),id.clone(UUID.randomUUID().toString()));
+//It will find out the objects that are primary key or not to be updated if you don't want to update your object do not
+// enter your object in updateData method but if you want to find the object via primary keys enter those and check
+//doNotUpdate on constructor creation.
-//It will find out the objects that are primary key or not to be updated if you don't want to update your object do not enter your object in updateData method but if you want to find the object via primary keys enter those and check doNotUpdate on constructor creation.
+ UpdateDataFunction update = (UpdateDataFunction) table.requestFunction(UpdateDataFunction.class);
+ update.values(name.clone("Mmd"), uid.clone(UUID.randomUUID().toString())).execute();
-database.updateData("workers",name.clone("Mmd"),id.clone(UUID.randomUUID().toString())));
+ SelectFunction select = (SelectFunction) table.requestFunction(SelectFunction.class);
+ SQLResult sql = select.where("worker", id.clone(myId)).execute();
-SQLResult sql = database.selectData("worker",id.clone(myId));
//SQLResult class does contain the result set but make sure to use SQLResult.close(); if your job was done.
+ }
+}
```
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..5e71754
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,30 @@
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
+plugins {
+ id("java")
+ id("com.github.johnrengelman.shadow") version "7.1.2"
+ kotlin("jvm") version "1.9.0"
+}
+
+group = "me.gameisntover"
+version = "1.1"
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ implementation("org.projectlombok:lombok:1.18.28")
+ annotationProcessor("org.projectlombok:lombok:1.18.28")
+ implementation(kotlin("stdlib-jdk8"))
+}
+tasks.shadowJar{
+ val compileKotlin: KotlinCompile by tasks
+ compileKotlin.kotlinOptions {
+ jvmTarget = "1.8"
+ }
+ val compileTestKotlin: KotlinCompile by tasks
+ compileTestKotlin.kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..249e583
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..ae04661
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..a69d9cb
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,240 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+APP_NAME="Gradle"
+APP_BASE_NAME=${0##*/}
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..f127cfd
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,91 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index d9ccb5b..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
- 4.0.0
-
- me.gameisntover
- SQLApi
- 1.1-SNAPSHOT
-
-
- 18
- 18
- UTF-8
-
-
-
- org.testng
- testng
- 7.6.1
- test
-
-
- org.projectlombok
- lombok
- 1.18.24
- provided
-
-
-
\ No newline at end of file
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..34a19eb
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1 @@
+rootProject.name = "KirbyQL"
diff --git a/src/main/java/me/gameisntover/database/Database.java b/src/main/java/me/gameisntover/kirbyql/database/Database.java
similarity index 71%
rename from src/main/java/me/gameisntover/database/Database.java
rename to src/main/java/me/gameisntover/kirbyql/database/Database.java
index 91bbf30..f5bf18c 100644
--- a/src/main/java/me/gameisntover/database/Database.java
+++ b/src/main/java/me/gameisntover/kirbyql/database/Database.java
@@ -1,38 +1,44 @@
-package me.gameisntover.database;
+package me.gameisntover.kirbyql.database;
import lombok.SneakyThrows;
+import me.gameisntover.kirbyql.database.table.SQLTable;
+import me.gameisntover.kirbyql.object.DBObject;
import java.io.File;
import java.sql.*;
import java.util.HashMap;
import java.util.Locale;
+import java.util.logging.Logger;
import static java.lang.System.out;
public abstract class Database {
+ private static final String SQLITE_PREFIX = "jdbc:sqlite:";
+ public final HashMap> objectMap = new HashMap<>();
+ private final Type type;
+ protected Connection con;
private String address;
private String dbName;
private String user;
private int port;
private String password;
- public Connection con;
- public static String SQLITE_PREFIX = "jdbc:sqlite:";
- private final Type type;
private File file;
-
- public HashMap> objectMap = new HashMap<>();
-
- public Database(File file) {
+ public final Logger log;
+ public Database(File file,Logger log) {
+ this(log,Type.SQLite);
this.file = file;
- type = Type.SQLite;
createConnection();
}
+ private Database(Logger log,Type type){
+ this.log = log;
+ this.type = type;
+ }
-
- public Database(DatabaseInfo info) {
- this.type = info.getDatabaseType();
+ public Database(DatabaseInfo info,Logger log) {
+ this(log,info.getDatabaseType());
+ ;
switch (info.getDatabaseType()) {
- case MySQL:
+ case MariaDB:
this.address = info.getAddress();
this.port = info.getPort();
this.dbName = info.getName();
@@ -51,8 +57,9 @@ public Database(DatabaseInfo info) {
}
}
+ @SafeVarargs
@SneakyThrows
- public void createNewTable(String tableName, DBObject... types) {
+ public final SQLTable createNewTable(String tableName, DBObject... types) {
createConnection();
StringBuilder builder = new StringBuilder("CREATE TABLE IF NOT EXISTS " + tableName + "(");
for (DBObject obj : types) {
@@ -73,17 +80,19 @@ public void createNewTable(String tableName, DBObject... types) {
out.println(sql);
e.printStackTrace();
}
+ return new SQLTable(tableName, this, types);
}
public void insertData(String tableName, DBObject>... objects) {
createConnection();
StringBuilder builder1 = new StringBuilder("INSERT IGNORE INTO ").append(tableName).append("(");
- if (type.equals(Type.SQLite)) builder1 = new StringBuilder("INSERT OR IGNORE INTO ").append(tableName).append("(");
+ if (type.equals(Type.SQLite))
+ builder1 = new StringBuilder("INSERT OR IGNORE INTO ").append(tableName).append("(");
StringBuilder builder2 = new StringBuilder(" VALUES(");
for (DBObject> obj : objects) {
builder1.append(obj.name.toLowerCase(Locale.ROOT));
if (obj.value instanceof String)
- builder2.append("\"").append(obj.value).append("\"");
+ builder2.append(obj.value);
else builder2.append(obj.value);
if (objects[objects.length - 1].equals(obj)) {
builder1.append(")");
@@ -109,14 +118,14 @@ public void insertData(String tableName, DBObject>... objects) {
public void updateData(String tableName, DBObject>... objects) {
createConnection();
StringBuilder builder1 = new StringBuilder("UPDATE OR IGNORE ").append(tableName).append(" SET ");
- if (type.equals(Type.MySQL)){
+ if (type.equals(Type.MariaDB)) {
builder1 = new StringBuilder("UPDATE IGNORE ").append(tableName).append(" SET ");
}
StringBuilder builder2 = new StringBuilder();
if (builder2.toString().length() == 0) builder2 = new StringBuilder(" WHERE ");
for (DBObject> obj : objects) {
if (obj.doNotUpdate) {
- builder2.append(obj.name).append("=").append(obj.value.toString());
+ builder2.append(obj.name).append("=").append(obj.value.toString());
if (objects[objects.length - 1].equals(obj)) {
builder2.append(";");
} else {
@@ -124,7 +133,7 @@ public void updateData(String tableName, DBObject>... objects) {
}
} else {
if (obj.value instanceof String)
- builder1.append(obj.name).append("=").append("\"").append(obj.value).append("\"");
+ builder1.append(obj.name).append("=").append(obj.value);
else builder1.append(obj.name).append("=").append(obj.value.toString());
if (objects[objects.length - 1].equals(obj)) {
builder2.append(";");
@@ -145,32 +154,34 @@ public void updateData(String tableName, DBObject>... objects) {
}
}
- @SneakyThrows
- public SQLResult selectData(String tableName, DBObject>... primaryKeys) {
+ public KirbyResult selectData(String tableName, DBObject>... primaryKeys) {
createConnection();
StringBuilder b1 = new StringBuilder("SELECT * FROM " + tableName);
- if (primaryKeys.length == 0){
+ if (primaryKeys.length == 0) {
b1.append(";");
- Statement stmt = con.createStatement();
- return new SQLResult(stmt.executeQuery(b1.toString()));
+ try {
+ Statement stmt = con.createStatement();
+ return new KirbyResult(stmt.executeQuery(b1.toString()));
+ } catch (SQLException e){
+ e.printStackTrace();
+ }
}
b1.append(" WHERE ");
for (DBObject> obj : primaryKeys) {
- if (obj.value instanceof String){
- b1.append(obj.name).append("=").append("\"").append(obj.value).append("\"").append(" ");
- }
- else b1.append(obj.name).append("=").append(obj.value).append(" ");
+ if (obj.value instanceof String) {
+ b1.append(obj.name).append("=").append(obj.value).append(" ");
+ } else b1.append(obj.name).append("=").append(obj.value).append(" ");
if (!primaryKeys[primaryKeys.length - 1].equals(obj)) {
b1.append(",");
} else {
b1.append(";");
}
}
- SQLResult sr = null;
+ KirbyResult sr = null;
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(b1.toString());
- sr = new SQLResult(rs);
+ sr = new KirbyResult(rs);
} catch (SQLException e) {
out.println(b1);
e.printStackTrace();
@@ -178,16 +189,14 @@ public SQLResult selectData(String tableName, DBObject>... primaryKeys) {
return sr;
}
- public enum Type {
- MySQL,
- SQLite
-
+ public Type getType() {
+ return type;
}
- public void createConnection() {
+ public Connection createConnection() {
try {
switch (type) {
- case MySQL:
+ case MariaDB:
String url = String.format("jdbc:mysql://%s:%d/%s", address, port, dbName);
con = DriverManager.getConnection(url, user, password);
break;
@@ -198,16 +207,25 @@ public void createConnection() {
} catch (SQLException e) {
e.printStackTrace();
}
+ return con;
}
- public DBObject defineColumn(String name,String type,boolean primaryKey){
- objectMap.put(name,DBObject.of(name,type,primaryKey,primaryKey));
+ public DBObject defineColumn(String name, String type, boolean primaryKey) {
+ objectMap.put(name, DBObject.of(name, type, primaryKey, primaryKey));
return objectMap.get(name);
}
- public DBObject getColumn(String name){
+ public DBObject getColumn(String name) {
return objectMap.get(name);
}
+ public enum Type {
+ MariaDB,
+ SQLite,
+
+ }
+ public Logger getLogger() {
+ return log;
+ }
}
diff --git a/src/main/java/me/gameisntover/database/DatabaseInfo.java b/src/main/java/me/gameisntover/kirbyql/database/DatabaseInfo.java
similarity index 68%
rename from src/main/java/me/gameisntover/database/DatabaseInfo.java
rename to src/main/java/me/gameisntover/kirbyql/database/DatabaseInfo.java
index aa007dd..cffa96b 100644
--- a/src/main/java/me/gameisntover/database/DatabaseInfo.java
+++ b/src/main/java/me/gameisntover/kirbyql/database/DatabaseInfo.java
@@ -1,7 +1,11 @@
-package me.gameisntover.database;
+package me.gameisntover.kirbyql.database;
+
+import lombok.experimental.SuperBuilder;
+import me.gameisntover.kirbyql.database.Database;
import java.io.File;
+@SuperBuilder
public class DatabaseInfo {
private final Database.Type databaseType;
private String name;
@@ -11,6 +15,26 @@ public class DatabaseInfo {
private int port;
private File file;
+
+
+ public DatabaseInfo(File file) {
+ databaseType = Database.Type.SQLite;
+ this.file = file;
+ }
+
+ public DatabaseInfo() {
+ this.databaseType = Database.Type.MariaDB;
+ }
+
+ public DatabaseInfo(String name, String address, int port, String user, String pass) {
+ this.name = name;
+ this.address = address;
+ this.port = port;
+ this.user = user;
+ this.pass = pass;
+ this.databaseType = Database.Type.MariaDB;
+ }
+
public int getPort() {
return port;
}
@@ -38,18 +62,4 @@ public Database.Type getDatabaseType() {
public File getFile() {
return file;
}
-
- public DatabaseInfo(File file){
- databaseType = Database.Type.SQLite;
- this.file = file;
- }
-
- public DatabaseInfo(String name,String address,int port,String user,String pass){
- this.name = name;
- this.address = address;
- this.port = port;
- this.user = user;
- this.pass = pass;
- this.databaseType = Database.Type.MySQL;
- }
}
diff --git a/src/main/java/me/gameisntover/database/SQLResult.java b/src/main/java/me/gameisntover/kirbyql/database/KirbyResult.java
similarity index 89%
rename from src/main/java/me/gameisntover/database/SQLResult.java
rename to src/main/java/me/gameisntover/kirbyql/database/KirbyResult.java
index 67eea3c..28800d6 100644
--- a/src/main/java/me/gameisntover/database/SQLResult.java
+++ b/src/main/java/me/gameisntover/kirbyql/database/KirbyResult.java
@@ -1,4 +1,4 @@
-package me.gameisntover.database;
+package me.gameisntover.kirbyql.database;
import lombok.SneakyThrows;
@@ -7,11 +7,11 @@
import java.sql.SQLException;
import java.sql.Statement;
-public class SQLResult {
+public class KirbyResult {
private final ResultSet rs;
private Statement stmt;
- protected SQLResult(ResultSet rs) {
+ public KirbyResult(ResultSet rs) {
this.rs = rs;
try {
if (rs != null && !rs.isClosed())
diff --git a/src/main/java/me/gameisntover/kirbyql/database/function/DeleteFunction.kt b/src/main/java/me/gameisntover/kirbyql/database/function/DeleteFunction.kt
new file mode 100644
index 0000000..196b320
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/function/DeleteFunction.kt
@@ -0,0 +1,49 @@
+package me.gameisntover.kirbyql.database.function
+
+import me.gameisntover.kirbyql.database.table.SQLTable
+import me.gameisntover.kirbyql.`object`.DBObject
+import java.sql.Connection
+import java.sql.SQLException
+
+class DeleteFunction(table: SQLTable) : SQLFunction(table) {
+ private val tableName: String
+ private var sql: String
+ private var sqlEnd = ";"
+
+ init {
+ this.tableName = table.name
+ sql = "DELETE FROM $tableName"
+ }
+
+ public fun where(vararg objects: DBObject<*>): DeleteFunction {
+ val builder = StringBuilder(" ")
+ if (objects.isNotEmpty()) builder.append("WHERE ")
+ for (obj in objects) {
+ builder.append(obj.name).append("=").append(obj.value.toString())
+ if (objects.last() != obj) builder.append(",")
+ }
+ sqlEnd = builder.toString() + sqlEnd
+ return this
+ }
+
+ override fun execute() {
+ val con: Connection = table.createConnection()
+ try {
+ val stmt = con.createStatement()
+ stmt.executeUpdate(getSQLCode())
+ stmt.close()
+ con.close()
+ } catch (e: SQLException) {
+ e.printStackTrace()
+ table.database.logger.info("SQL Code: ${getSQLCode()}")
+ }
+ }
+
+ override fun getSQLCode(): String {
+ return sql + sqlEnd
+ }
+
+ override fun toString(): String {
+ return getSQLCode()
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/gameisntover/kirbyql/database/function/InsertDataFunction.kt b/src/main/java/me/gameisntover/kirbyql/database/function/InsertDataFunction.kt
new file mode 100644
index 0000000..2ab01e3
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/function/InsertDataFunction.kt
@@ -0,0 +1,44 @@
+package me.gameisntover.kirbyql.database.function
+
+import me.gameisntover.kirbyql.database.Database
+import me.gameisntover.kirbyql.database.table.SQLTable
+import me.gameisntover.kirbyql.`object`.DBObject
+
+class InsertDataFunction(table: SQLTable, ignore: Boolean) : SQLFunction(table) {
+ private var sqlA = "INSERT "
+
+ init {
+ if (ignore) {
+ sqlA += if (table.database.type.equals(Database.Type.SQLite)) "OR IGNORE INTO ${table.name}("
+ else "IGNORE INTO ${table.name}("
+ }
+ }
+
+ override fun execute() {
+ val con = table.createConnection()
+ val stmt = con.createStatement();
+ stmt.executeUpdate(sqlA)
+ stmt.close()
+ con.close()
+ }
+
+ fun values(vararg objects: DBObject<*>): InsertDataFunction {
+ val builder = StringBuilder(sqlA)
+ val builder2 = StringBuilder(") VALUES(")
+ for (obj in objects) {
+ builder.append(obj.name)
+ if (obj.value is String) builder2.append("\"").append(obj.value).append("\"")
+ else builder2.append(obj.value)
+
+ if (obj == objects.last()) {
+ builder2.append(")")
+ }
+ }
+ sqlA = builder.toString() + builder2.toString()
+ return this
+ }
+
+ override fun getSQLCode(): String {
+ return sqlA
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/gameisntover/kirbyql/database/function/SQLFunction.kt b/src/main/java/me/gameisntover/kirbyql/database/function/SQLFunction.kt
new file mode 100644
index 0000000..f100e2b
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/function/SQLFunction.kt
@@ -0,0 +1,8 @@
+package me.gameisntover.kirbyql.database.function
+
+import me.gameisntover.kirbyql.database.table.SQLTable
+
+abstract class SQLFunction(val table: SQLTable) {
+ abstract fun execute()
+ abstract fun getSQLCode(): String
+}
\ No newline at end of file
diff --git a/src/main/java/me/gameisntover/kirbyql/database/function/SQLResultFunction.kt b/src/main/java/me/gameisntover/kirbyql/database/function/SQLResultFunction.kt
new file mode 100644
index 0000000..19e1b00
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/function/SQLResultFunction.kt
@@ -0,0 +1,13 @@
+package me.gameisntover.kirbyql.database.function
+
+import me.gameisntover.kirbyql.database.KirbyResult
+import me.gameisntover.kirbyql.database.table.SQLTable
+import me.gameisntover.kirbyql.exception.SQLFunctionException
+
+abstract class SQLResultFunction(table: SQLTable) : SQLFunction(table) {
+ abstract fun executeQuery(): KirbyResult
+
+ override fun execute() {
+ throw SQLFunctionException("You can't execute a SQLResultFunction")
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/gameisntover/kirbyql/database/function/SelectFunction.kt b/src/main/java/me/gameisntover/kirbyql/database/function/SelectFunction.kt
new file mode 100644
index 0000000..26effc7
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/function/SelectFunction.kt
@@ -0,0 +1,65 @@
+package me.gameisntover.kirbyql.database.function
+
+import me.gameisntover.kirbyql.database.KirbyResult
+import me.gameisntover.kirbyql.database.table.SQLTable
+import me.gameisntover.kirbyql.`object`.DBObject
+import java.sql.Connection
+import java.sql.ResultSet
+import java.sql.SQLException
+
+class SelectFunction(table: SQLTable) : SQLResultFunction(table) {
+ private var sqlA = "SELECT * FROM ${table.name}"
+ private var rsType = ResultSet.TYPE_SCROLL_SENSITIVE
+ private var rsCon = ResultSet.CONCUR_READ_ONLY
+
+ override fun executeQuery(): KirbyResult {
+ val con: Connection = table.createConnection()
+ var sr: KirbyResult? = null
+ try {
+ val stmt = con.createStatement(rsType,rsCon)
+ val rs = stmt.executeQuery(getSQLCode())
+ rs.next();
+ sr = KirbyResult(rs)
+ } catch (e: SQLException) {
+ e.printStackTrace()
+ table.database.logger.info("SQL Code: ${getSQLCode()}")
+ }
+ return checkNotNull(sr)
+ }
+
+ fun where(vararg primaryKeys: DBObject<*>): SelectFunction {
+ val b1 = StringBuilder(sqlA)
+ b1.append(" WHERE ")
+ for (obj in primaryKeys) {
+ if (obj.value is String) {
+ b1.append(obj.name).append("=").append("\"").append(obj.value).append("\"").append(" ")
+ } else b1.append(obj.name).append("=").append(obj.value).append(" ")
+ if (primaryKeys[primaryKeys.size - 1] != obj) {
+ b1.append(",")
+ } else {
+ b1.append(" ")
+ }
+ }
+ sqlA = b1.toString()
+ return this
+ }
+
+ fun limit(limit: Int): SelectFunction {
+ sqlA += " LIMIT $limit"
+ return this;
+ }
+
+ fun order(row: String, desc: Boolean = false): SelectFunction {
+ val b1 = StringBuilder(sqlA)
+ b1.append(" ORDER BY $row")
+ if (desc)
+ b1.append(" DESC")
+ sqlA = b1.toString()
+ return this
+ }
+
+ override fun getSQLCode(): String {
+ return sqlA
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/me/gameisntover/kirbyql/database/function/UpdateDataFunction.kt b/src/main/java/me/gameisntover/kirbyql/database/function/UpdateDataFunction.kt
new file mode 100644
index 0000000..0d27227
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/function/UpdateDataFunction.kt
@@ -0,0 +1,58 @@
+package me.gameisntover.kirbyql.database.function
+import me.gameisntover.kirbyql.database.Database
+import me.gameisntover.kirbyql.database.table.SQLTable
+import me.gameisntover.kirbyql.`object`.DBObject
+
+
+class UpdateDataFunction(table: SQLTable, ignore: Boolean) : SQLFunction(table) {
+ private var sqlA = ""
+
+ init {
+ if (ignore) {
+ sqlA += if (table.database.type.equals(Database.Type.SQLite)) "OR IGNORE ${table.name}"
+ else "UPDATE ${table.name}"
+ }
+ }
+
+ override fun execute() {
+ val con = table.createConnection()
+ val stmt = con.createStatement()
+ sqlA += ";"
+ stmt.executeUpdate(sqlA)
+ stmt.close()
+ con.close()
+ }
+
+ fun values(vararg objects: DBObject<*>): UpdateDataFunction {
+ val builder = StringBuilder(" SET ")
+ for (obj in objects) {
+ builder.append(obj.name).append("=")
+ if (obj.value is String) builder.append("\"").append(obj.value).append("\"")
+ else builder.append(obj.value)
+ if (obj != objects.last()) {
+ builder.append(", ")
+ }
+ }
+ sqlA += builder.toString()
+ return this
+ }
+
+ fun where(vararg objects: DBObject<*>): UpdateDataFunction {
+ val builder = StringBuilder(" WHERE ")
+ for (obj in objects) {
+ builder.append(obj.name).append("=")
+ if (obj.value is String) builder.append("\"").append(obj.value).append("\"")
+ else builder.append(obj.value)
+ if (obj != objects.last()) {
+ builder.append(", ")
+ }
+ }
+ sqlA += builder.toString()
+ return this
+ }
+
+ override fun getSQLCode(): String {
+ return sqlA
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/me/gameisntover/kirbyql/database/table/SQLTable.java b/src/main/java/me/gameisntover/kirbyql/database/table/SQLTable.java
new file mode 100644
index 0000000..f876507
--- /dev/null
+++ b/src/main/java/me/gameisntover/kirbyql/database/table/SQLTable.java
@@ -0,0 +1,142 @@
+package me.gameisntover.kirbyql.database.table;
+
+import me.gameisntover.kirbyql.database.Database;
+import me.gameisntover.kirbyql.database.KirbyResult;
+import me.gameisntover.kirbyql.database.function.DeleteFunction;
+import me.gameisntover.kirbyql.database.function.SQLResultFunction;
+import me.gameisntover.kirbyql.database.function.SQLFunction;
+import me.gameisntover.kirbyql.database.function.SelectFunction;
+import lombok.SneakyThrows;
+import me.gameisntover.kirbyql.object.DBObject;
+import org.jetbrains.annotations.NotNull;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Locale;
+import java.util.logging.Logger;
+
+
+public class SQLTable {
+ private final Database database;
+ private final String tableName;
+ private final DBObject>[] objects;
+
+ public SQLTable(String name, Database database, DBObject>... objects) {
+ this.tableName = name;
+ this.objects = objects;
+ this.database = database;
+ }
+
+ public void insertData(DBObject>... objects) {
+ Connection con = database.createConnection();
+ StringBuilder builder1 = new StringBuilder("INSERT IGNORE INTO ").append(tableName).append("(");
+ if (database.getType().equals(Database.Type.SQLite))
+ builder1 = new StringBuilder("INSERT OR IGNORE INTO ").append(tableName).append("(");
+ StringBuilder builder2 = new StringBuilder(" VALUES(");
+ for (DBObject> obj : objects) {
+ builder1.append(obj.name.toLowerCase(Locale.ROOT));
+ if (obj.value instanceof String) {
+ builder2.append("\"").append(obj.value).append("\"");
+ } else builder2.append(obj.value);
+ if (objects[objects.length - 1].equals(obj)) {
+ builder1.append(")");
+ builder2.append(");");
+ } else {
+ builder1.append(",");
+ builder2.append(",");
+ }
+ }
+ String sql = builder1.append(builder2).toString();
+ try {
+ Statement stmt = con.createStatement();
+ stmt.executeUpdate(sql);
+ stmt.close();
+ con.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ database.getLogger().info("SQL Code: " + sql);
+ }
+ }
+
+ @SneakyThrows
+ public void updateData(DBObject>... objects) {
+ Connection con = database.createConnection();
+ StringBuilder builder1 = new StringBuilder("UPDATE OR IGNORE ").append(tableName).append(" SET ");
+ if (database.getType().equals(Database.Type.MariaDB)) {
+ builder1 = new StringBuilder("UPDATE IGNORE ").append(tableName).append(" SET ");
+ }
+ StringBuilder builder2 = new StringBuilder();
+ if (builder2.toString().length() == 0) builder2 = new StringBuilder(" WHERE ");
+ for (DBObject> obj : objects) {
+ if (obj.doNotUpdate) {
+ if (obj.value instanceof String)
+ builder2.append(obj.name).append("=").append("\"").append(obj.value).append("\"");
+ else builder2.append(obj.name).append("=").append(obj.value.toString());
+ if (objects[objects.length - 1].equals(obj)) {
+ builder2.append(";");
+ } else {
+ builder2.append(",");
+ }
+ } else {
+ if (obj.value instanceof String)
+ builder1.append(obj.name).append("=").append("\"").append(obj.value).append("\"");
+ else builder1.append(obj.name).append("=").append(obj.value);
+ if (objects[objects.length - 1].equals(obj)) {
+ builder2.append(";");
+ } else {
+ builder1.append(",");
+ }
+ }
+ }
+ String sql = builder1.append(builder2).toString();
+ try {
+ Statement stmt = con.createStatement();
+ stmt.executeUpdate(sql);
+ stmt.close();
+ con.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ getLogger().info("SQL Code: " + sql);
+ }
+ }
+
+
+ public KirbyResult selectData(DBObject>... primaryKeys) {
+ SelectFunction func = new SelectFunction(this).where(primaryKeys);
+ return func.executeQuery();
+ }
+
+ @SafeVarargs
+ public final void deleteData(DBObject