編寫MYSQL外掛程式 UDF 使其實現Split函式

2021-07-09 12:54:27 字數 2256 閱讀 3311

mysql udf外掛程式好像不能返回結果集

mfc dll工程, 靜態庫鏈結, unicode字元編碼

新建cpp, **如下

#include "stdafx.h"

#include "tokenize.h"

#include "mysql/mysql.h"

#include #ifdef _debug

#define new debug_new

#endif

void ucs2_to_utf8(std::string &dst, const std::wstring &src)

else if (t <= 0x7ff)

else

}return;

}void utf8_to_ucs2(std::wstring &dst, const std::string &src)

switch (n)

break;

case 2:

break;

case 3:

break;

default:

return;

} }return;

}void splitstringtoarray(lpctstr lpstring, lpctstr lptoken, cstringarray &elelist)

}using namespace std;

#define max_result_length 128

#define udfapi extern "c" __declspec(dllexport)

udfapi my_bool tokenize_init(udf_init *init, udf_args *args, char *msg)

else }

udfapi void tokenize_deinit(udf_init *init)

// only vaild for string function

udfapi char* tokenize(udf_init *init, udf_args *args, char *result, unsigned long *length, char *is_null, char *error)

else

}

註冊函式(檔案需要放到mysql的lib/plugin目錄下)

create function tokenize returns string soname '***.dll';

測試**

select tokenize("123|1", "|", 0);

刪除函式

drop function tokenize;

函式引數說明:

第乙個引數: 待處理字串

第二個引數:分隔符, 支援多個(用mfc的好處)

第三個引數:取結果的第幾個

返回值: 分割後的結果, 若無結果(下標越界), 返回null

配合乙個儲存過程, 實現類似split函式, 返回表

drop procedure if exists `split`;

create definer = `root`@`localhost` procedure `split`(in `p_text` text,in `p_delim` text)

begin

declare e varchar(128);

declare i int default(0);

create temporary table if not exists __split_tmptable(`element` varchar(128), primary key(`element`));

truncate __split_tmptable;

select tokenize(p_text, p_delim, i) into e;

set i = i + 1;

while not isnull(e) do

insert into __split_tmptable values(e);

select tokenize(p_text, p_delim, i) into e;

set i = i + 1;

end while;

select * from __split_tmptable;

end;

UDF提權 mysql外掛程式學習筆記

以前看過一篇老外的文章講mysql udf提權原理,這篇文章中針對kali自帶的mysql 提權udf.dll進行了解釋,但是並沒有介紹如何編寫乙個標準的udf擴充套件。後來有個朋友託我幫他改下udf.dll,把其他功能去掉,只留下cmd shell這個命令執行的功能 開始我以為隨便寫個dll,然後...

編寫jQuery外掛程式 實現返回頂部外掛程式

國慶過去一周多了,作為it界的具有嚴重 工作狂 性質的宅人,居然還沒走出玩耍的心情,拖了程式猿的腳後跟了。最近工作不順,心情不佳,想吐槽下公司,想了還是厚道點,以彼之道還施彼身,覺得自己也和他們同流合汙了!就做個 沉默 的程式猿吧!總有一天會猿球崛起 嘿嘿。牢騷到底為止,好的心情才是重要的,本來猝死...

mysql索引及其實現原理筆記

1 mysql索引的型別 mysql主要有以下幾種索引型別 fulltext,hash,btree,rtree。hash 只能用於等值查詢,不能用於範圍查詢。btree,rtree 可用於等值查詢 範圍查詢,btree為mysql的預設索引型別。2 索引種類 普通索引 唯一索引 主鍵索引 組合索引 ...