update 部分功能完成。 开始做最麻烦的where 了..- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- :main
- call :create table test "姓名,日期,年龄,date" values "玉清,1984-1-1,28,test123"
- echo create+insert后
- set %table_name%
- call :update test set "姓名,年龄" = "陆海,31"
- echo update后
- set %table_name%
- goto :eof
-
-
-
- :create table [table_name] [(sum1,sum2,...)] values [(sum1,sum2,...)]
- rem 返回0创建成功,%cs%,%cn%,%table_name%可以直接调用,返回1表示已经存在该表,返回2表示数值太长,返回3表示创建初始数值错误
- 1>nul 2>nul set %2 && exit /b 1
- set "table_name=%2"
- set "cs=%~3"
- set "cs=!cs:,= !"
- set /a cn=0
- for %%i in (!cs!) do (
- set /a cn+=1
- set /a %%i=!cn!
- )
- set "!table_name!_ !cs!=table" || exit /b 2
- if %4.==values. (
- call :insert into !table_name! %5 || exit /b 3
- )
- exit /b 0
- goto :eof
-
- :insert into [table_name] [(sum1,sum2,...)] values [(sum1,sum2,...)]
- rem 返回0插入数值成功,返回1该表不存在,返回2插入数值超过表项,超出部分被丢弃,返回3插入数值变量失败。
- 1>nul 2>nul set %2 || exit /b 1
- set "table_name=%2"
- set is=%~3
- set is=!is:,= !
- set /a in=0
- if %4.==values. call :scinsert %3 %5
- for %%i in (!is!) do (
- set /a in+=1
- if !in! gtr !cn! exit /b 2
- if !in! lss 2 (set "iis=%table_name%_ %%i") else ( set "iis=!iis! %%i")
- )
- set "%iis%=values" || exit /b 3
- exit /b 0
- goto :eof
-
-
- :scinsert [(sum1,sum2,...)] [(sum1,sum2,...)]
- rem 选择部分KEY插入值,其它值如果没有就用nul填充,保留功能。
- goto :eof
-
-
- rem ===================================================================================\
- rem update 功能
- :update [table] set key = values "where ..."
- 1>nul 2>nul set %1 || exit /b 1
- set "table_name=%1"
- set "key=%~3"
- set "values=%~4"
- set "run=%~5"
- set "tokens="
- for %%i in (!key!) do set "tokens=!tokens! !%%i!"
- set "str1="
- for /f "delims=*" %%i in ('set !table_name!_ ^| findstr /v "=table$"') do (
- set "str1=%%i"
- set "str1=!str1:~0,-7!"
- set "str1=!str1:%table_name%_= !"
- call :shift !str1!
- call :reset %%i
- )
- goto :eof
- rem ===================================================================================/
- rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- rem ===================================================================================\
- rem 定位到准确key的函数
- rem 想到了新的方法, findstr "\<num\>" 来对照字符位置,tokens来定位替换字符串
- :shift [str]
- set "str="
- set /a nxn=0
- set /a bk=1
- set /a tk=0
- for %%i in (%*) do (
- set /a nxn+=1
- echo;!tokens! | findstr "\<!nxn!\>" >nul && set /a bk=0
- if !bk! equ 0 (
- set /a tk+=1
- call :shift2 !tk!
- ) else ( set "str=!str! %%i" )
- )
- goto :eof
- rem 替换某个位置values的函数
- :shift2 [num]
- for /f "tokens=%1 delims=," %%x in ("!values!") do (
- set "str=!str! %%x"
- set /a bk=1
- )
- goto :eof
- rem =====================================================================================/
-
-
- :reset [str]
- set "xh=%*"
- set "!xh:~0,-7!="
- set "%table_name%_!str!=values"
- goto :eof
-
-
- rem =====================================================================================\
- :select value* from [table_name] [where ...]
- set "table_name=%3"
- rem select * from table1 where field1 like ’%value1%’
- goto :eof
- rem =====================================================================================/
-
-
-
-
- rem =====================================================================================\
- :delete from [table] [where ...]
- goto :eof
- rem =====================================================================================/
-
-
-
-
- rem =====================================================================================\
- :save
- rem 保存数据库到文件。
- goto :eof
- rem =====================================================================================/
复制代码
|