dbd/postgresql/connection.c

changeset 4
c50b0e6f25d6
parent 3
b61020ca4753
child 13
10c8c6f0da14
equal deleted inserted replaced
3:b61020ca4753 4:c50b0e6f25d6
29 29
30 if (pport >= 1 && pport <= 65535) { 30 if (pport >= 1 && pport <= 65535) {
31 snprintf(portbuf, sizeof(portbuf), "%d", pport); 31 snprintf(portbuf, sizeof(portbuf), "%d", pport);
32 port = portbuf; 32 port = portbuf;
33 } else { 33 } else {
34 luaL_error(L, "Invalid port %d", pport); 34 luaL_error(L, DBI_ERR_INVALID_PORT, pport);
35 } 35 }
36 } 36 }
37 case 4: 37 case 4:
38 if (lua_isnil(L, 4) == 0) 38 if (lua_isnil(L, 4) == 0)
39 host = luaL_checkstring(L, 4); 39 host = luaL_checkstring(L, 4);
53 conn->postgresql = PQsetdbLogin(host, port, options, tty, db, user, password); 53 conn->postgresql = PQsetdbLogin(host, port, options, tty, db, user, password);
54 conn->statement_id = 0; 54 conn->statement_id = 0;
55 55
56 if (PQstatus(conn->postgresql) != CONNECTION_OK) { 56 if (PQstatus(conn->postgresql) != CONNECTION_OK) {
57 lua_pushnil(L); 57 lua_pushnil(L);
58 lua_pushfstring(L, "Failed to connect to database: %s", PQerrorMessage(conn->postgresql)); 58 lua_pushfstring(L, DBI_ERR_CONNECTION_FAILED, PQerrorMessage(conn->postgresql));
59 return 2; 59 return 2;
60 } 60 }
61 61
62 luaL_getmetatable(L, DBD_POSTGRESQL_CONNECTION); 62 luaL_getmetatable(L, DBD_POSTGRESQL_CONNECTION);
63 lua_setmetatable(L, -2); 63 lua_setmetatable(L, -2);
109 if (conn->postgresql) { 109 if (conn->postgresql) {
110 return dbd_postgresql_statement_create(L, conn, luaL_checkstring(L, 2)); 110 return dbd_postgresql_statement_create(L, conn, luaL_checkstring(L, 2));
111 } 111 }
112 112
113 lua_pushnil(L); 113 lua_pushnil(L);
114 lua_pushstring(L, "Database not available"); 114 lua_pushstring(L, DBI_ERR_DB_UNAVAILABLE);
115 return 2; 115 return 2;
116 } 116 }
117 117
118 /* 118 /*
119 * __gc 119 * __gc

mercurial