invalid null pointer!

图片说明

// win_cDemo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "tinyxml.h"
#include "NLPIR.h"
#include <stdio.h>
#include <stdlib.h>
#include<windows.h>
#include <fstream>
#include <iostream>
#include <string>
#include <hash_map>

#include <WinSock.h>
#include <mysql.h>

using namespace std;
#pragma comment(lib,"tinyxml.lib")
#pragma comment(lib, "NLPIR.lib")
#pragma comment(lib, "ws2_32.lib")   
#pragma comment(lib, "libmysql.lib") 

//存放字典数据的hashMap
hash_map<string,float> hmDic;
//计算运行时间的变量
DWORD start_time,end_time;
//mysql文件
MYSQL mysqlData;
string user,passwd;



void processDictionary(string filename,float weight)
{
    ifstream fin(filename.c_str());  
    if( !fin ) 
    {   
        cout << "Error opening " << filename << " for input" << endl;   
        return;  
    }
    string buf;
    while(fin>>buf)
    {
        hmDic.insert(make_pair(buf,weight));
    }
    cout<<"Process Dictionary "<<filename<<" Success"<<endl;
}


void processConfigure()
{
    //获取XML对象
    TiXmlDocument doc; 
    //装载文件
    doc.LoadFile("configure.xml");
    //获取dics
    TiXmlElement *dicsLevel = (doc.RootElement())->FirstChildElement();
    //获取dic
    TiXmlElement *dicLevel=dicsLevel->FirstChildElement();
    TiXmlElement *pathLevel,*weightLevel;
    start_time = GetTickCount64();//获取开始时间
    cout<<"Process Begin, Please Wait Patient"<<endl;
    while (dicLevel != NULL)//
    {
        pathLevel = dicLevel->FirstChildElement();//获取path
        weightLevel = pathLevel->NextSiblingElement();//获取weight        
        //cout<<pathLevel->GetText()<<":"<<weightLevel->GetText()<<endl;
        //处理文本
        string filename =pathLevel->GetText();
        float weight = atof(weightLevel->GetText());
        //cout<<filename<<"|"<<weight+1<<endl;
        processDictionary(filename,weight);
        dicLevel=dicLevel->NextSiblingElement();
    }
    end_time = GetTickCount64();//获取结束时间
    cout<<"Process All Dictionary Use "<<end_time-start_time<<" ms"<<endl;

    //获取mysql
    TiXmlElement *mysqlLevel = dicsLevel->NextSiblingElement();
    TiXmlElement *userLevel,*passwdLevel;

    userLevel = mysqlLevel->FirstChildElement();//获取user
    passwdLevel = userLevel->NextSiblingElement();//获取passwd
    user = userLevel->GetText();
    passwd = passwdLevel->GetText();


}


int sentenceAnalysis(string sSentence)
{
    try
    {
        const result_t *pVecResult;
        int nCount;
        //对句子进行分词
        pVecResult=NLPIR_ParagraphProcessA(sSentence.c_str(),&nCount);
        float totalNum = 0;//句子总的情感值
        float tmpNum = 0;//每个字句的情感值
        float tmpD = 1;//用来存放临时副词的变量
        bool isTmpDSet = 0;//是否有副词被设置
        for (int i=0;i<nCount;i++)
        {

            string ciXin = pVecResult[i].sPOS;//词性
            //不存在词性则跳过
            if(ciXin.empty())
            {
                continue;
            }


            //词性中包含'w'(即标点符号),表示当前的一个子句已经处理完毕
            if(ciXin[0]=='w')
            {
                totalNum += tmpNum;
                tmpNum = 0;
                continue;
            }

            //如果不是形容词a,副词d,动词v,名词n,数词m,则不处理
            if(!(ciXin=="a"||ciXin=="d"||ciXin=="v"||ciXin=="n"||ciXin=="m"))
                continue;

            string tmp = sSentence.substr(pVecResult[i].start,pVecResult[i].length);

            auto itr=hmDic.find(tmp);
            if(itr!=hmDic.end())
            {
                if(ciXin=="d")//如果副词后面接副词,进行多重复合
                {
                    tmpD *= itr->second;
                    isTmpDSet = 1;
                }
                else if(isTmpDSet)//如果之前存在副词
                {
                    tmpNum += tmpD * itr->second;
                    isTmpDSet = 0;
                }
                else
                {
                    tmpNum += itr->second;//不存在副词的影响,直接加减
                }

            }

        }

        return totalNum;
    }
    catch(...)
    {
        //对出错的情况进行默认处理
        return 0;
    }

}

void initMysql()
{
    try
    {
        mysql_init(&mysqlData);

        // localhost:服务器 root为账号,123456为密码 test为数据库名 3306为端口
        if(!mysql_real_connect(&mysqlData, "localhost","root","","fooddata",3306,NULL,0)) 
        {

            cout<<"database connect fail"<<endl;
            exit(1);
        } 
        else
            cout<<"database connect success"<<endl;

    }
    catch (...)
    {
        exit(1);
    }
}


int main()
{
    //初始化分词器
    if(!NLPIR_Init()) 
    {
        printf("Init fails\n");
        return -1;
    }

    //首先读取配置文件,建立字典数据
    processConfigure();

    //初始化mysql数据库
    initMysql();

    //存储每一行数据
    string text;

    //查询所有结果
    string sqlstr = "SELECT id,text,kind FROM comment";  
    MYSQL_RES *result = NULL;  
    if (0 == mysql_query(&mysqlData, sqlstr.c_str())) 
    {  

        //一次性取得数据集   
        result = mysql_store_result(&mysqlData);   
        //获取每一行
        MYSQL_ROW row = NULL;  
        row = mysql_fetch_row(result);  

        start_time = GetTickCount64();
        while (NULL != row) {  

            text = row[1];
            //对每个句子进行分词
            int answer = sentenceAnalysis(text);

            if(answer>0)
                cout<<"正面评价"<<endl;
            else if(answer<0)
                cout<<"负面评价"<<endl;
            else
                cout<<"中性评价"<<endl;


            row = mysql_fetch_row(result);  
        }  

        end_time = GetTickCount64();

        cout<<"Text all rows use "<<end_time-start_time<<" ms"<<endl;

    }
    //关闭数据库
  // mysql_close(&mysqlData);

   //释放分词器资源
    NLPIR_Exit();
    return 0;

} 

求大神看看这个怎么修改???

3个回答

调试方式运行程序,看错误在哪一行,检查这一行的指针

你需要把你的宕机堆栈贴出来

就是停止到这里,不知道如何解决了

`static size_t __CLRCALL_OR_CDECL length(const _Elem *_First)
{ // find length of null-terminated string
return (*_First == 0 ? 0
: _CSTD strlen(_First));
}


Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
invalid null pointer

编写双向链表产生的无效空指针![图片](https://img-ask.csdn.net/upload/201705/03/1493780812_162445.jpg)

munmap_chunk(): invalid pointer

![图片说明](https://img-ask.csdn.net/upload/201904/06/1554550406_562231.png) 42 //析构函数 43 MyString::~MyString() 44 { 45 cout<<"MyString::~MyString():"<<endl; 46 if (p != NULL) 47 { 48 delete []p; 49 p = NULL; 50 } 51 size = 1; 52 } 46行判断p不为空为真,进入删除却出现错误“munmap_chunk(): invalid pointer 已放弃 (核心已转储)”,有大佬解释一下么?万分感谢!!!

在TDengine中执行SQL语句,提示DB error: invalid table id

aarch32系统、ubuntu(x86),两个系统都构建过TDengine-1.6.5.6。 首先,在ubuntu(x86)系统里,执行官方 ``` demotaosdemo -h xxx.xxx.xx.xx ``` 向aarch32系统中的数据库,插入10亿条测试数据。 成功插入之后,我分别在aarch32系统执行taos、ubuntu(x86)系统执行 ``` taos -h xxx.xx.xx.xx ``` 进入终端执行sql,分别得到两个不同的结果。 (x86)系统提示DB error: invalid table id。 这是什么造成的呢? 截图如下: ![图片说明](https://img-ask.csdn.net/upload/202005/08/1588905276_941480.jpg)

全志A33通过ffmpeg调用摄像头出现的问题

[VFE]..........................vfe clk open!....................... [VFE]vfe_open ok [VFE_ERR]input index(-1) > dev->dev_qty(1)-1 invalid! [VFE]vfe_close Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = ee0a8000 [00000000] *pgd=74c42831enable-gpl --enable-nonfree --en Internal error: Oops: 17 [#1] PREEMPT SMP ARM

在应用程序中处理NULL值并发送到数据库

<div class="post-text" itemprop="text"> <p>I have nullable variables I'm trying to use in my app, and also send to a database which has columns that are default null.</p> <p>This is a sample struct:</p> <pre><code>// Location type type Location struct { ID int `schema:"id"` Title *string `schema:"title"` } </code></pre> <p>Title is defined as *string, as it could be null (e.g. no user input or client app sends it as null).</p> <p>Here’s my function receiving form data:</p> <pre><code>// JSONLocationCreate func func (a *App) JSONLocationCreate(w http.ResponseWriter, r *http.Request) { r.ParseForm() var e Location err := decoder.Decode(&amp;e, r.PostForm) if err != nil { respondWithError(w, http.StatusBadRequest, "Invalid request payload") return } // --- SUCCESS --- // If e.Title has data, the following line works. // --- FAIL --- // If e.Title doesn’t have data (for whatever reason), it’s null, and crashes the app: log.Println(*e.Title) // Ultimately the variable would be sent off to a database. // Below I’m removing other functions and such, just including my statement line. // --- SUCCESS --- // If e.Title has data, the following line works. // --- FAIL --- // If e.Title is null (e.g. no user input), this crashes the app. statement := fmt.Sprintf("INSERT INTO locations(title) VALUES('%s')", *e.Title) // In either case, the crash error is similar to this: // panic serving [::1]:52459: runtime error: invalid memory address or nil pointer dereference } </code></pre> <p><strong>CONCERN 1:</strong> How can I make use of nullable variables (like e.Title), throughout the app, without throwing panic errors when the variable is null? Is the best practice to wrap it in a function that converts null to “” strings? How can such a function be applied transparently, so I don’t have to have something like “nullCheck(*e.Title)” on every instance of the variable?</p> <p><strong>CONCERN 2:</strong> In the case of my DB queries, I can’t be sending “” string values into the database in place of nulls. Up to now my queries are manually built. I suppose I need a function to generate the SQL queries automatically excluding columns and variables when the variables are null.</p> <p>Am I on the right track? Any examples?</p> <p>I haven’t understood all the threads/tutorials after hours of searching.</p> </div>

Nullptr 到底是什么?

<div class="post-text" itemprop="text"> <p>We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new <code>nullptr</code>.</p> <p>Well, no need anymore for the nasty macro <code>NULL</code>.</p> <pre><code>int* x = nullptr; myclass* obj = nullptr; </code></pre> <p>Still, I am not getting how <code>nullptr</code> works. For example, <a href="http://en.wikipedia.org/wiki/C%2B%2B11#Null_pointer_constant" rel="noreferrer">Wikipedia article</a> says:</p> <blockquote> <p>C++11 corrects this by introducing a new <strong>keyword</strong> to serve as a distinguished null pointer constant: nullptr. It is of <strong>type nullptr_t</strong>, which is implicitly convertible and comparable to any pointer type or pointer-to-member type. It is not implicitly convertible or comparable to integral types, except for bool.</p> </blockquote> <p>How is it a keyword and an instance of a type?</p> <p>Also, do you have another example (beside the Wikipedia one) where <code>nullptr</code> is superior to good old <code>0</code>?</p> </div> <p>转载于:https://stackoverflow.com/questions/1282295/what-exactly-is-nullptr</p>

PHP客户端和Golang服务器中的Apache Thrift错误

<div class="post-text" itemprop="text"> <p>when i use Apache Thrift PHP client and PHP server is OK, but When I use Golang as Server, is not OK, I find nothing in the internet that about Golang thrift use Http mode,The document only show the usage about socket mode in Golang,so i need help.</p> <p>php server code(use laravel5.2, thrift 0.11.0):</p> <pre><code> try{ header('Content-Type', 'application/x-thrift'); $dokuHandler = new DokuService(); $multiplexedProcessor = new TMultiplexedProcessor(); // 创建多个服务Processor $dokuProcessor = new DokuServiceProcessor($dokuHandler); // 将服务注册到TMultiplexedProcessor中 $multiplexedProcessor-&gt;registerProcessor("doku", $dokuProcessor); // 初始化数据传输方式transport $transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W)); // 利用该传输方式初始化数据传输格式protocol $protocol = new TBinaryProtocol($transport, true, true); // 开始服务 $transport-&gt;open(); $multiplexedProcessor-&gt;process($protocol, $protocol); } catch (\TException $exception) { Log::error("DokuService handleRequest", [ 'request' =&gt; $request, 'exMsg' =&gt; $exception-&gt;getMessage(), 'exStack' =&gt; $exception-&gt;getTraceAsString(), ]); } finally { if ($transport) { $transport-&gt;close(); } } </code></pre> <p>php client code:</p> <pre><code>public function __construct() { $this-&gt;transport = null; try { $uri = '/rpc/outgo/server'; $serviceName = 'outgo'; $host = self::getHost(); $port = self::getPort(); $socket = new THttpClient($host, $port, $uri); $this-&gt;transport = new TBufferedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($this-&gt;transport); $this-&gt;multiplexedProtocol = new TMultiplexedProtocol($protocol, $serviceName); parent::__construct($this-&gt;multiplexedProtocol); } catch (\Exception $e) { Log::error('construct OutgoRpcClient error', [ 'host' =&gt; $host, 'port' =&gt; $port, 'serviceName' =&gt; $serviceName, 'ex_msg' =&gt; $e-&gt;getMessage(), 'ex_trace' =&gt; $e-&gt;getTraceAsString(), ]); } } </code></pre> <p>golang server code(go1.10.3, gin framework,):</p> <pre><code>func RpcReceive(c *gin.Context) { //defer func() { // if err := recover(); err != nil { // config.LogRecord.WithFields(logrus.Fields{"error": err}).Error("rpc worker error") // } //}() var transport thrift.TTransport newTransport, err := thrift.NewTBufferedTransportFactory(10).GetTransport(transport) if err != nil { panic("new transport error") } protocol := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(newTransport) orderProcessor := orderservice.NewOrderServiceProcessor(new(orderService)) OrderServiceName := "outgo" multiProcessor := thrift.NewTMultiplexedProcessor() multiProcessor.RegisterProcessor(OrderServiceName, orderProcessor) newTransport.Open() multiProcessor.Process(c, protocol, protocol) //newTransport.Close() } </code></pre> <p>golang err:</p> <pre><code> runtime error: invalid memory address or nil pointer dereference /usr/local/opt/go/libexec/src/runtime/panic.go:502 (0x102ad08) gopanic: reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz)) /usr/local/opt/go/libexec/src/runtime/panic.go:63 (0x1029d7d) panicmem: panic(memoryError) /usr/local/opt/go/libexec/src/runtime/signal_unix.go:388 (0x1040279) sigpanic: panicmem() /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/git.apache.org/thrift.git/lib/go/thrift/buffered_transport.go:58 (0x18c180a) (*TBufferedTransport).Open: return p.tp.Open() /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/controller/rpc/receiveBusiness.go:86 (0x18ce4cf) RpcReceive: newTransport.Open() /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/context.go:104 (0x1537b42) (*Context).Next: c.handlers[c.index](c) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/middleware/catchPanic.go:41 (0x16b2e20) RecoveryWithWriter.func1: c.Next() /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/context.go:104 (0x1537b42) (*Context).Next: c.handlers[c.index](c) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/middleware/commonMw.go:16 (0x16b40a4) Logger.func1: c.Next() /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/context.go:104 (0x1537b42) (*Context).Next: c.handlers[c.index](c) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/gin.go:332 (0x153ebe4) (*Engine).handleHTTPRequest: context.Next() /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/gin.go:296 (0x153e432) (*Engine).ServeHTTP: engine.handleHTTPRequest(c) /usr/local/opt/go/libexec/src/net/http/server.go:2694 (0x128093b) serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) /usr/local/opt/go/libexec/src/net/http/server.go:1830 (0x127caf0) (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) /usr/local/opt/go/libexec/src/runtime/asm_amd64.s:2361 (0x1057030) goexit: BYTE $0x90 // NOP ] &lt;nil&gt;} goroutine 33 [running]: net/http.(*conn).serve.func1(0xc4202da000) /usr/local/opt/go/libexec/src/net/http/server.go:1726 +0xd0 panic(0x1b06940, 0xc42033e5a0) /usr/local/opt/go/libexec/src/runtime/panic.go:502 +0x229 github.com/rule-engine/rule-engine/vendor/github.com/sirupsen/logrus.Entry.log(0xc4200d52c0, 0xc4202f4630, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/sirupsen/logrus/entry.go:126 +0x2d2 github.com/rule-engine/rule-engine/vendor/github.com/sirupsen/logrus.(*Entry).Panic(0xc42033e410, 0xc42056b640, 0x1, 0x1) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/sirupsen/logrus/entry.go:194 +0xaa github.com/rule-engine/rule-engine/vendor/github.com/sirupsen/logrus.(*Logger).Panic(0xc4200d52c0, 0xc42056b640, 0x1, 0x1) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/sirupsen/logrus/logger.go:244 +0x6d github.com/rule-engine/rule-engine/app/http/middleware.RecoveryWithWriter.func1.1(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/middleware/catchPanic.go:35 +0x46b panic(0x19db200, 0x21320b0) /usr/local/opt/go/libexec/src/runtime/panic.go:502 +0x229 github.com/rule-engine/rule-engine/vendor/git.apache.org/thrift.git/lib/go/thrift.(*TBufferedTransport).Open(0xc420248080, 0xc4202f4510, 0x1b241cf) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/git.apache.org/thrift.git/lib/go/thrift/buffered_transport.go:58 +0x2a github.com/rule-engine/rule-engine/app/http/controller/rpc.RpcReceive(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/controller/rpc/receiveBusiness.go:86 +0x370 github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin.(*Context).Next(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/context.go:104 +0x43 github.com/rule-engine/rule-engine/app/http/middleware.RecoveryWithWriter.func1(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/middleware/catchPanic.go:41 +0x51 github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin.(*Context).Next(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/context.go:104 +0x43 github.com/rule-engine/rule-engine/app/http/middleware.Logger.func1(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/app/http/middleware/commonMw.go:16 +0x85 github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin.(*Context).Next(0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/context.go:104 +0x43 github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc4200dc6c0, 0xc42037e580) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/gin.go:332 +0x585 github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc4200dc6c0, 0x1c29ae0, 0xc42038c000, 0xc42015a000) /usr/local/var/www/go/src/github.com/rule-engine/rule-engine/vendor/github.com/gin-gonic/gin/gin.go:296 +0x153 net/http.serverHandler.ServeHTTP(0xc4200dc7e0, 0x1c29ae0, 0xc42038c000, 0xc42015a000) /usr/local/opt/go/libexec/src/net/http/server.go:2694 +0xbc net/http.(*conn).serve(0xc4202da000, 0x1c2a860, 0xc4201da4c0) /usr/local/opt/go/libexec/src/net/http/server.go:1830 +0x651 created by net/http.(*Server).Serve /usr/local/opt/go/libexec/src/net/http/server.go:2795 +0x27b </code></pre> <p>I refer php server to write golang server code.</p> </div>

ioutil.ReadAll惨败

<div class="post-text" itemprop="text"> <p>I'm trying to get an io.Reader back from this weather it's a link or a path I'm given. For some context I'm using flags</p> <pre><code>func getString(link, path string) (io.Reader, error) { var dick io.ReadWriter if link != "" { resp, err := http.Get(link) if err != nil { return nil, err } io.Copy(dick, resp.Body) } if path != "" { file, err := os.Open(path) if err != nil { return nil, err } io.Copy(dick, file) } return dick, nil } </code></pre> <p>and boom</p> <pre><code>panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x46e949] </code></pre> <p>this bad boy comes along</p> </div>

急!GIT clone的时候报错

git.exe clone --branch hjws --progress -v "git@172.72.101.189:gxfw-project.git" "D:\GXHJWS" Cloning into 'D:\GXHJWS'... 0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487 AllocationBase 0x0, BaseAddress 0x68570000, RegionSize 0x2D0000, State 0x10000 C:\Program Files (x86)\Git\bin\ssh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 0 fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. git did not exit cleanly (exit code 128) (938 ms @ 2016/8/25 10:13:29)

mycat 调用存储过程 出现问题。

使用mycat实现读写分离 ,简单查询没有问题,命令行中调用存储过程会返回结果但不结束查询。需要按ctrl+c才能中止,并且java后台调用时不返回查询结果。 ![图片说明](https://img-ask.csdn.net/upload/201902/18/1550476695_611838.png) 现在已有数据库hostM1(作为主数据库)和hostS2(作为从数据库),以通过mysql自带的功能实现主从复制,现mycat的配置如下: **server.xml :** ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mycat:server SYSTEM "server.dtd"> <mycat:server xmlns:mycat="http://io.mycat/"> <system> <property name="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 --> <property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 --> <property name="sequnceHandlerType">2</property> <property name="processorBufferPoolType">0</property> <property name="handleDistributedTransactions">0</property> <property name="useOffHeapForMerge">1</property> <property name="memoryPageSize">1m</property> <property name="spillsFileBufferSize">1k</property> <property name="useStreamOutput">0</property> <property name="systemReserveMemorySize">384m</property> <property name="useZKSwitch">true</property> </system> <user name="csuser"> <property name="password">cspassword</property> <property name="schemas">csdb</property> </user> </mycat:server> ``` **schema.xml:** ``` <?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="csuser" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"> </schema> <dataNode name="dn1" dataHost="localhost1" database="csdb" /> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1" url="" user="" password=""> <readHost host="hostS2" url="" user="" password="" /> </writeHost> </dataHost> </mycat:schema> ``` **测试用存储过程test_prock()** ``` CREATE PROCEDURE `test_prock`() BEGIN SELECT title FROM wx_article_title; END ``` 执行存储过程 ``` /*!mycat:db_type=master*/call test_prock(); ``` **rule.xml**(没有配置分片) ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mycat:rule SYSTEM "rule.dtd"> <mycat:rule xmlns:mycat="http://io.mycat/"> <tableRule name="rule1"> <rule> <columns>id</columns> <algorithm>func1</algorithm> </rule> </tableRule> <tableRule name="rule2"> <rule> <columns>user_id</columns> <algorithm>func1</algorithm> </rule> </tableRule> <tableRule name="sharding-by-intfile"> <rule> <columns>sharding_id</columns> <algorithm>hash-int</algorithm> </rule> </tableRule> <tableRule name="auto-sharding-long"> <rule> <columns>id</columns> <algorithm>rang-long</algorithm> </rule> </tableRule> <tableRule name="mod-long"> <rule> <columns>id</columns> <algorithm>mod-long</algorithm> </rule> </tableRule> <tableRule name="sharding-by-murmur"> <rule> <columns>id</columns> <algorithm>murmur</algorithm> </rule> </tableRule> <tableRule name="crc32slot"> <rule> <columns>id</columns> <algorithm>crc32slot</algorithm> </rule> </tableRule> <tableRule name="sharding-by-month"> <rule> <columns>create_time</columns> <algorithm>partbymonth</algorithm> </rule> </tableRule> <tableRule name="latest-month-calldate"> <rule> <columns>calldate</columns> <algorithm>latestMonth</algorithm> </rule> </tableRule> <tableRule name="auto-sharding-rang-mod"> <rule> <columns>id</columns> <algorithm>rang-mod</algorithm> </rule> </tableRule> <tableRule name="jch"> <rule> <columns>id</columns> <algorithm>jump-consistent-hash</algorithm> </rule> </tableRule> <function name="murmur" class="io.mycat.route.function.PartitionByMurmurHash"> <property name="seed">0</property><!-- 默认是0 --> <property name="count">2</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 --> <property name="virtualBucketTimes">160</property><!-- 一个实际的数据库节点被映射为这么多虚拟节点,默认是160倍,也就是虚拟节点数是物理节点数的160倍 --> </function> <function name="crc32slot" class="io.mycat.route.function.PartitionByCRC32PreSlot"> <property name="count">2</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 --> </function> <function name="hash-int" class="io.mycat.route.function.PartitionByFileMap"> <property name="mapFile">partition-hash-int.txt</property> </function> <function name="rang-long" class="io.mycat.route.function.AutoPartitionByLong"> <property name="mapFile">autopartition-long.txt</property> </function> <function name="mod-long" class="io.mycat.route.function.PartitionByMod"> <!-- how many data nodes --> <property name="count">3</property> </function> <function name="func1" class="io.mycat.route.function.PartitionByLong"> <property name="partitionCount">8</property> <property name="partitionLength">128</property> </function> <function name="latestMonth" class="io.mycat.route.function.LatestMonthPartion"> <property name="splitOneDay">24</property> </function> <function name="partbymonth" class="io.mycat.route.function.PartitionByMonth"> <property name="dateFormat">yyyy-MM-dd</property> <property name="sBeginDate">2015-01-01</property> </function> <function name="rang-mod" class="io.mycat.route.function.PartitionByRangeMod"> <property name="mapFile">partition-range-mod.txt</property> </function> <function name="jump-consistent-hash" class="io.mycat.route.function.PartitionByJumpConsistentHash"> <property name="totalBuckets">3</property> </function> </mycat:rule> ```

GoLang GraphQL无法从nil文字中告知nil指针

<div class="post-text" itemprop="text"> <p>In my GoLang GraphQL query, I have the following method (takes user id and returns profile data):</p> <pre><code> "userProfile": &amp;graphql.Field{ Type: UserProfileType, Args: graphql.FieldConfigArgument{ "uid": &amp;graphql.ArgumentConfig{ Type: graphql.Int, }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { uid := p.Args["uid"].(int) u, err := db.GetUserProfile(p.Context.Value(handler.CtxId("currentUser")).(int), uid) return u, err }, }, </code></pre> <p>When user id is invalid <code>db.GetUserProfile</code> returns nil pointer <code>u</code> and nil error <code>err</code>, but GraphQL responds the following:</p> <pre><code>{ "data": { "userProfile": null }, "errors": [ { "message": "runtime error: invalid memory address or nil pointer dereference", "locations": [] } ] } </code></pre> <p>Although when I modify GraphQL code like this (explicit nil check and return literal):</p> <pre><code>... u, err := db.GetUserProfile(p.Context.Value(handler.CtxId("currentUser")).(int), uid) if u == nil { return nil, err } return u, err </code></pre> <p>everything works as expected and GraphQL returns this:</p> <pre><code>{ "data": { "userProfile": null } } </code></pre> <p>How do I manage without explicit checking for nil and teach GraphQL to distinguish nil pointer from nil literal? </p> </div>

无法在GORM中设置“多对多”关联

<div class="post-text" itemprop="text"> <p>I'm trying to set up an association between <code>User</code>s and <code>PredictionsBag</code>s. My problem is that everything works OK if I use GORM's assumed names for referring objects, but I'd like to change the names a bit.</p> <pre class="lang-golang prettyprint-override"><code>type User struct { gorm.Model // We’ll try not using usernames for now Email string `gorm:"not null;unique_index"` Password string `gorm:"-"` PasswordHash string `gorm:"not null"` Remember string `gorm:"-"` // A user’s remember token. RememberHash string `gorm:"not null;unique_index"` Bags []PredictionsBag } </code></pre> <p>Every user, of course, owns zero or more <code>PredictionsBag</code>s:</p> <pre class="lang-golang prettyprint-override"><code>type PredictionsBag struct { gorm.Model UserID uint // I want this to be "OwnerID" Title string NotesPublic string `gorm:"not null"` // Markdown field. May be published. NotesPrivate string `gorm:"not null"` // Markdown field. Only for (private) viewing and export. Predictions []Prediction } </code></pre> <p>And I'd like to have <code>.Related()</code> work in the usual way:</p> <pre class="lang-golang prettyprint-override"><code>func (ug *userGorm) ByEmail(email string) (*User, error) { var ret User matchingEmail := ug.db.Where("email = ?", email) err := first(matchingEmail, &amp;ret) if err != nil { return nil, err } var bags []PredictionsBag if err := ug.db.Model(&amp;ret).Related(&amp;bags).Error; err != nil { return nil, err } ret.Bags = bags return &amp;ret, nil } </code></pre> <p>My problem is that I can't find a way to change <code>PredictionsBag.UserID</code> to anything else and still have GORM figure out the relationships involved. I've been reading <a href="http://gorm.io/docs/has_many.html#Foreign-Key" rel="nofollow noreferrer">http://gorm.io/docs/has_many.html#Foreign-Key</a> and if I change the relevant lines to</p> <pre class="lang-golang prettyprint-override"><code>type User struct { // … Bags []PredictionsBag `gorm:"foreignkey:OwnerID"` } </code></pre> <p>and</p> <pre class="lang-golang prettyprint-override"><code>type PredictionsBag struct { // … OwnerID uint // … } </code></pre> <p>I get this error:</p> <pre><code>[2019-07-28 14:23:49] invalid association [] </code></pre> <p>What am I doing wrong? I've also been reading <a href="http://gorm.io/docs/belongs_to.html" rel="nofollow noreferrer">http://gorm.io/docs/belongs_to.html</a>, but I'm not sure which page to follow more closely.</p> </div>

ExtJS4.0问题

弹出窗口第一个正常 第二次报错 Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLDivElement.insertBefore] [在此错误处中断] target.insertBefore(item.el.dom, position || null); 求指导

c语言警告问题,主函数里有一个警告

#include<stdio.h> #include <malloc.h> #include <conio.h> #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 #define QueueElementType BitTree typedef int DataType; typedef struct BitNode { DataType data; struct BitNode *LChild; struct BitNode *RChild; }BitNode,*BitTree; typedef struct Node {QueueElementType data; struct Node *next; }LinkQueueNode; typedef struct BitTree {LinkQueueNode *front; LinkQueueNode *rear; }LinkQueue; int InitQueue(LinkQueue *Q)/*将Q初始化为一个空的链队列*/ {Q->front=(LinkQueueNode*)malloc(sizeof(LinkQueueNode)); if(Q->front!=NULL) {Q->rear=Q->front; Q->front->next=NULL; return(TRUE); } else return(FALSE);/*溢出*/ } int EnterQueue(LinkQueue *Q,QueueElementType x) {LinkQueueNode *NewNode; NewNode=(LinkQueueNode*)malloc(sizeof(LinkQueueNode)); if(NewNode!=NULL) {NewNode->data=x; NewNode->next=NULL; Q->rear->next=NewNode; Q->rear=NewNode; return(TRUE); } else return(FALSE);/*溢出*/ } int DeleteQueue(LinkQueue *Q,QueueElementType *x) {LinkQueueNode *p; if(Q->front==Q->rear) return(FALSE); p=Q->front->next; Q->front->next=p->next;/*队头元素出队*/ if(Q->rear==p) Q->rear=Q->front; *x=p->data; free(p); return(TRUE); } int IsEmpty(LinkQueue *Q) {if((Q->front)==(Q->rear)) return TRUE; else return FALSE; } int CreatBiTree(BitTree *bt)/*用扩展先序遍历序列创建二叉树,如果是#当前树根置为空,否则申请一个新节点*/ { char ch; do {scanf("%c",&ch); }while(ch=='\n'); if(ch=='0') *bt=NULL; else { *bt=(BitTree)malloc(sizeof(BitNode)); (*bt)->data=ch; CreatBiTree(&((*bt)->LChild)); CreatBiTree(&((*bt)->RChild)); } return OK; } void Visit(char ch)/*访问根节点*/ { printf("%c",ch); } void PreOrder(BitTree root) /*先序遍历二叉树, root为指向二叉树(或某一子树)根结点的指针*/ { if (root!=NULL) { Visit(root ->data); /*访问根结点*/ PreOrder(root ->LChild); /*先序遍历左子树*/ PreOrder(root ->RChild); /*先序遍历右子树*/ } } void InOrder(BitTree root) /*中序遍历二叉树, root为指向二叉树(或某一子树)根结点的指针*/ { if (root!=NULL) { InOrder(root ->LChild); /*中序遍历左子树*/ Visit(root ->data); /*访问根结点*/ InOrder(root ->RChild); /*中序遍历右子树*/ } } void PostOrder(BitTree root) /* 后序遍历二叉树,root为指向二叉树(或某一子树)根结点的指针*/ { if(root!=NULL) { PostOrder(root ->LChild); /*后序遍历左子树*/ PostOrder(root ->RChild); /*后序遍历右子树*/ Visit(root ->data); /*访问根结点*/ } } int LayerOrder(BitTree bt) {LinkQueue Q; BitTree p; InitQueue(&Q);/*初始化队列*/ if(bt==NULL) return ERROR;/*二叉树为空树则结束遍历*/ EnterQueue(&Q,bt);/*二叉树非空则根节点bt入队,开始层次遍历*/ while(IsEmpty(&Q)!=1) /*若队列非空则遍历继续*/ {DeleteQueue(&Q,&p);/*对头元素出对并访问*/ Visit(p->data); if(p->LChild!=NULL) EnterQueue(&Q,p->LChild);/*若p的左孩子非空则入队*/ if(p->RChild!=NULL) EnterQueue(&Q,p->RChild); } return OK; } void path(BitTree root,char r) {BitNode *p,*q; int i,top=0; BitTree s[50]; q=NULL; p=root; while(p!=NULL||top!=0) {while(p!=NULL) {top++; if(top>=50) exit(0); s[top]=p; p=p->LChild; } if(top>0) {p=s[top]; if(p->RChild==NULL||p->RChild==q) {if(p->data==r) {for(i=1;i<=top;i++) printf("%c",s[i]->data); return ; } else {q=p; top--; p=NULL; } } else p=p->RChild; } } } int main() { BitTree T; int h,x; char *r; printf("请选择一下内容:\n"); printf("1.建立二叉树的存储结构。\n"); printf("2.求二叉树先序遍历序列。\n"); printf("3.求二叉树中序遍历序列。\n"); printf("4.求二叉树后序遍历序列。\n"); printf("5.求二叉树的层序遍历序列。\n"); printf("6.求根节点到指定节点的路径。\n"); do{ printf("请做出选择:"); scanf("%d",&h); switch(h) {case 1:printf("请输入二叉树中的元素(以扩展先序遍历序列输入,其中.代表空子树):\n"); CreatBiTree(&T);break; case 2:printf("先序遍历序列为:"); PreOrder(T);break; case 3:printf("\n中序遍历序列为:"); InOrder(T);break; case 4:printf("\n后序遍历序列为:"); PostOrder(T);break; case 5:printf("\n层序遍历序列为:"); LayerOrder(T); break; case 6:printf("\n根节点到指定节点的路径:"); scanf("%c",&r); path(T,r); break; } }while(h!=0); printf("退出"); } [Warning] passing arg 2 of `path' makes integer from pointer without a cast 这个警告怎么处理啊!!!

openssl移植到armBN_mod_inverse:no inverse

Openssl RSA编程代码在pc机上可以正常运行。 交叉编译到ARM 上会有错误, 错误信息error:0306E06C:bignum routines:BN_mod_inverse:no inverse。求大神指教。 ``RSA *rsa = NULL; BIO *bio = NULL; int rsa_len = 0; int num = 0; if ((bio = BIO_new_mem_buf((void *)PubKeyAuth, -1)) == NULL) { return RSA_ENCRYPT_ERROR; } if ((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)) == NULL) { return RSA_ENCRYPT_ERROR; } BIO_free_all(bio); rsa_len = RSA_size(rsa); num = RSA_public_encrypt(rsa_len, (unsigned char *)str, (unsigned char *)SendMessageBuff, rsa, RSA_PKCS1_PADDING ); if (num < 0) { return RSA_ENCRYPT_ERROR; } RSA_free(rsa); return num;` ```

安装 tengine异常,求解

请教大神!!! 安装tengine-2.2.0 异常 src/event/ngx_event_openssl.c: In function ‘ngx_ssl_init’: src/event/ngx_event_openssl.c:112:5: error: ‘OPENSSL_config’ is deprecated [-Werror=deprecated-declarations] OPENSSL_config(NULL); ^ In file included from /usr/local/include/openssl/ct.h:13:0, from /usr/local/include/openssl/ssl.h:61, from src/event/ngx_event_openssl.h:15, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/conf.h:92:1: note: declared here DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name)) ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_rsa512_key_callback’: src/event/ngx_event_openssl.c:753:9: error: ‘RSA_generate_key’ is deprecated [-Werror=deprecated-declarations] key = RSA_generate_key(512, RSA_F4, NULL, NULL); ^ In file included from /usr/local/include/openssl/rsa.h:13:0, from /usr/local/include/openssl/x509.h:31, from /usr/local/include/openssl/ssl.h:50, from src/event/ngx_event_openssl.h:15, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/rsa.h:193:1: note: declared here DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_dhparam’: src/event/ngx_event_openssl.c:943:11: error: dereferencing pointer to incomplete type ‘DH {aka struct dh_st}’ dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL); ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_handshake’: src/event/ngx_event_openssl.c:1166:31: error: dereferencing pointer to incomplete type ‘SSL {aka struct ssl_st}’ if (c->ssl->connection->s3) { ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_connection_error’: src/event/ngx_event_openssl.c:1928:21: error: ‘SSL_R_NO_CIPHERS_PASSED’ undeclared (first use in this function) || n == SSL_R_NO_CIPHERS_PASSED /* 182 */ ^ src/event/ngx_event_openssl.c:1928:21: note: each undeclared identifier is reported only once for each function it appears in src/event/ngx_event_openssl.c: In function ‘ngx_ssl_session_cache’: src/event/ngx_event_openssl.c:2122:43: error: passing argument 2 of ‘SSL_CTX_sess_set_get_cb’ from incompatible pointer type [-Werror=incompatible-pointer-types] SSL_CTX_sess_set_get_cb(ssl->ctx, ngx_ssl_get_cached_session); ^ In file included from src/event/ngx_event_openssl.h:15:0, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/ssl.h:637:6: note: expected ‘SSL_SESSION * (*)(struct ssl_st *, const unsigned char *, int, int *) {aka struct ssl_session_st * (*)(struct ssl_st *, const unsigned char *, int, int *)}’ but argument is of type ‘SSL_SESSION * (*)(SSL *, u_char *, int, int *) {aka struct ssl_session_st * (*)(struct ssl_st *, unsigned char *, int, int *)}’ void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_session_id_context’: src/event/ngx_event_openssl.c:2144:27: error: storage size of ‘md’ isn’t known EVP_MD_CTX md; ^ src/event/ngx_event_openssl.c:2210:5: error: implicit declaration of function ‘EVP_MD_CTX_cleanup’ [-Werror=implicit-function-declaration] EVP_MD_CTX_cleanup(&md); ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_session_ticket_key_callback’: src/event/ngx_event_openssl.c:2872:9: error: ‘RAND_pseudo_bytes’ is deprecated [-Werror=deprecated-declarations] RAND_pseudo_bytes(iv, 16); ^ In file included from /usr/local/include/openssl/engine.h:19:0, from src/event/ngx_event_openssl.h:22, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/rand.h:47:1: note: declared here DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num)) ^ cc1: all warnings being treated as errors objs/Makefile:827: recipe for target 'objs/src/event/ngx_event_openssl.o' failed make[1]: *** [objs/src/event/ngx_event_openssl.o] Error 1 make[1]: Leaving directory '/home/hvm/桌面/Lib/tengine-tengine-2.2.0' Makefile:15: recipe for target 'install' failed make: *** [install] Error 2

Golang:零类型的防御性接口

<div class="post-text" itemprop="text"> <p>I recently found some go code was running in a test framework where there were some uninitialized variables.</p> <p>This lead to a panic, which had a stack trace containing some c code at the top.</p> <p>Is there a way, in functions, that we can concisely detect wether the struct which is referenced as the implementing member is nil? i.e. </p> <pre><code>func ( d *Dog ) canBark Bool { //if d is nil, cryptic exception is thrown. //is there a way to defend against this? } </code></pre> <p>The error which is thrown is </p> <pre><code>panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0x4ec83a] goroutine 16 [running]: runtime.panic(0x9b7400, 0xf7ddf3) </code></pre> <p>It seems that in go, such lower level errors should occur very rarely, maybe never at all...</p> <p>There might be a Golang way to deal with nil references which don't clutter the code too much with if/else logic. For example, in java, you can wrap a large code segment in a null pointer exception handler.</p> </div>

Golang Filepath.Walk在大型目录上出现恐慌错误

<div class="post-text" itemprop="text"> <p>I am trying to walk through all files on the C drive which I read <em>can</em> be inefficient in Go, but I can't work out why I keep getting a panic error when doing this as I tell the walk function to return a nil error code. </p> <pre><code>package files import ( "path/filepath" "os" "fmt" ) func walkpath(path string, f os.FileInfo, err error) error { fmt.Printf("%s with %d bytes ", path,f.Size()) return nil } func GetFiles() { err := filepath.Walk("C:\\", walkpath) if err != nil { fmt.Printf(err.Error()) } } </code></pre> <p>Panic error: </p> <pre><code>panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x40 pc=0x46d0d6] goroutine 1 [running]: files.walkpath(0xc0820a8f80, 0xf, 0x0, 0x0, 0x664270, 0xc082408840, 0x0, 0x0) C:/project/src/files/files.go:11 +0x66 path/filepath.walk(0x529140, 0x3, 0x6641e8, 0xc082012240, 0x560d50, 0x0, 0x0) c:/go/src/path/filepath/path.go:370 +0x41c path/filepath.Walk(0x529140, 0x3, 0x560d50, 0x0, 0x0) c:/go/src/path/filepath/path.go:396 +0xe8 files.GetFiles() C:/project/src/files/files.go:22 +0xc9 main.main() c:/project/src/main.go:12 +0x49 exit status 2 c:\project&gt;go build c:\project\src\main.go </code></pre> <p><a href="https://gobyexample.com/panic" rel="nofollow">https://gobyexample.com/panic</a></p> <p>How do you handle errors which occur during runtime? </p> <p>Thanks!</p> </div>

使用GoLang在具有json类型字段的Postgres中创建表

<div class="post-text" itemprop="text"> <p>I am using GoLang in the back-end and PostgreSQL as a database. I'm new to PostgreSQL database connections with Go. I'm using <a href="https://beego.me/docs/intro/" rel="nofollow noreferrer">Beego</a> as a back-end. I want to create a table with one of a fields of JSON type using Golang <a href="https://golang.org/pkg/database/sql/" rel="nofollow noreferrer">database/sql</a> package and <a href="https://godoc.org/github.com/lib/pq" rel="nofollow noreferrer">lib/pq</a>. That what I do </p> <p>This is my create table query</p> <pre><code>createtable:= `CREATE TABLE apply_leave1 ( leaveid serial PRIMARY KEY NOT NULL , empid varchar(10) NOT NULL , leavedays double precision NOT NULL DEFAULT 0 , mdays double precision NOT NULL DEFAULT 0 , leavetype varchar(20) NOT NULL DEFAULT '' , daytype text NOT NULL '', leavefrom timestamp with time zone NOT NULL, leaveto timestamp with time zone NOT NULL, applieddate timestamp with time zone NOT NULL, leavestatus varchar(15) NOT NULL DEFAULT '' , resultdate timestamp with time zone, certificatestatus bool NOT NULL DEFAULT FALSE certificate json NULL)` conn := fmt.Sprintf( "user=%s password=%s dbname=%s sslmode=disable", "postgres", "root", "employee") log.Println("Creating a new connection: %v", conn) db, err := sql.Open("postgres", conn) stmt, err1 := db.Prepare(createtable) defer stmt.Close() _, err = stmt.Exec() if err != nil { fmt.Println(err.Error() } } </code></pre> <p>This is throwing me the following error</p> <blockquote> <p>Handler crashed with error runtime error: invalid memory address or nil pointer dereference</p> </blockquote> <p>But when I'm using query to select something from the table there is no problem with table creation query or other executed sql code. I appreciate any help. Thanks!</p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

你以为这样写Java代码很6,但我看不懂

为了提高 Java 编程的技艺,我最近在 GitHub 上学习一些高手编写的代码。下面这一行代码(出自大牛之手)据说可以征服你的朋友,让他们觉得你写的代码很 6,来欣赏一下吧。 IntStream.range(1, 5).boxed().map(i -&gt; { System.out.print("Happy Birthday "); if (i == 3) return "dear NAME"...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

立即提问
相关内容推荐