コード例 #1
0
ファイル: ls_firebird.c プロジェクト: hugohuang1111/moai-dev
/*
** Returns a table of column types from the query
** Lua Returns:
**   a table of column types
**   nil and error message otherwise.
*/
static int cur_coltypes (lua_State *L) {
    int i;
    XSQLVAR *var;
    cur_data *cur = getcursor(L,1);

    lua_newtable(L);

    for (i=1, var = cur->out_sqlda->sqlvar; i <= cur->out_sqlda->sqld; i++, var++) {
        lua_pushnumber(L, i);
        switch(var->sqltype & ~1) {
        case SQL_VARYING:
        case SQL_TEXT:
        case SQL_TYPE_TIME:
        case SQL_TYPE_DATE:
        case SQL_TIMESTAMP:
        case SQL_BLOB:
            lua_pushstring(L, "string");
            break;
        case SQL_SHORT:
        case SQL_LONG:
        case SQL_INT64:
        case SQL_FLOAT:
        case SQL_DOUBLE:
            lua_pushstring(L, "number");
            break;
        default:
            lua_pushstring(L, "unknown");
            break;
        }
        lua_settable(L, -3);
    }

    return 1;
}
コード例 #2
0
ファイル: ls_oci8.c プロジェクト: Abyss116/luaplus51-all
/*
** Push the number of rows.
*/
static int cur_numrows (lua_State *L) {
	int n;
	cur_data *cur = getcursor (L);
	ASSERT (L, OCIAttrGet ((dvoid *) cur->stmthp, OCI_HTYPE_STMT, (dvoid *)&n,
		(ub4)0, OCI_ATTR_NUM_ROWS, cur->errhp), cur->errhp);
	lua_pushnumber (L, n);
	return 1;
}
コード例 #3
0
ファイル: ls_sqlite.c プロジェクト: 0w/moai-dev
/*
** Get another row of the given cursor.
*/
static int cur_fetch (lua_State *L) {
	cur_data *cur = getcursor(L);
    sqlite_vm *vm = cur->sql_vm;
    const char **row = NULL;
    int res;

    if (vm == NULL)
        return 0;

    res = sqlite_step(vm, NULL, &row, NULL);

    /* no more results? */
    if (res == SQLITE_DONE)
        return finalize(L, cur);

    if (res != SQLITE_ROW)
        return finalize(L, cur);

	if (lua_istable (L, 2))
    {
		int i;
		const char *opts = luaL_optstring(L, 3, "n");

		if (strchr(opts, 'n') != NULL)
        {
			/* Copy values to numerical indices */
			for (i = 0; i < cur->numcols;)
            {
                lua_pushstring(L, row[i]);
				lua_rawseti(L, 2, ++i);
			}
        }
		if (strchr(opts, 'a') != NULL)
        {
			/* Copy values to alphanumerical indices */
            lua_rawgeti(L, LUA_REGISTRYINDEX, cur->colnames);

			for (i = 0; i < cur->numcols; i++)
            {
				lua_rawgeti(L, -1, i+1);
                lua_pushstring(L, row[i]);
				lua_rawset (L, 2);
			}
        }
		lua_pushvalue(L, 2);
		return 1; /* return table */
	}
	else
    {
		int i;
		luaL_checkstack (L, cur->numcols, LUASQL_PREFIX"too many columns");
		for (i = 0; i < cur->numcols; ++i)
			lua_pushstring(L, row[i]);
		return cur->numcols; /* return #numcols values */
	}
}
コード例 #4
0
ファイル: ls_mysql.cpp プロジェクト: RayHuo/iASP
/*
** Get another row of the given cursor.
*/
static int cur_fetch (lua_State *L) {
	cur_data *cur = getcursor (L);
	MYSQL_RES *res = cur->my_res;
	unsigned long *lengths;
	MYSQL_ROW row = mysql_fetch_row(res);
	if (row == NULL) {
		lua_pushnil(L);  /* no more results */
		return 1;
	}
	lengths = mysql_fetch_lengths(res);

	if (lua_istable (L, 2)) {
		const char *opts = luaL_optstring (L, 3, "n");
		if (strchr (opts, 'n') != NULL) {
			/* Copy values to numerical indices */
			int i;
			for (i = 0; i < cur->numcols; i++) {
				pushvalue (L, row[i], lengths[i]);
				lua_rawseti (L, 2, i+1);
			}
		}
		if (strchr (opts, 'a') != NULL) {
			int i;
			/* Check if colnames exists */
			if (cur->colnames == LUA_NOREF)
		        create_colinfo(L, cur);
			lua_rawgeti (L, LUA_REGISTRYINDEX, cur->colnames);/* Push colnames*/
	
			/* Copy values to alphanumerical indices */
			for (i = 0; i < cur->numcols; i++) {
				lua_rawgeti(L, -1, i+1); /* push the field name */

				/* Actually push the value */
				pushvalue (L, row[i], lengths[i]);
				lua_rawset (L, 2);
			}
			/* lua_pop(L, 1);  Pops colnames table. Not needed */
		}
		lua_pushvalue(L, 2);
		return 1; /* return table */
	}
	else {
		int i;
		luaL_checkstack (L, cur->numcols, LUASQL_PREFIX"too many columns");
		for (i = 0; i < cur->numcols; i++)
			pushvalue (L, row[i], lengths[i]);
		return cur->numcols; /* return #numcols values */
	}
}
コード例 #5
0
ファイル: ls_oci8.c プロジェクト: Abyss116/luaplus51-all
/*
** Get another row of the given cursor.
*/
static int cur_fetch (lua_State *L) {
	cur_data *cur = getcursor (L);
	sword status = OCIStmtFetch (cur->stmthp, cur->errhp, 1,
		OCI_FETCH_NEXT, OCI_DEFAULT);

	if (status == OCI_NO_DATA) {
		/* No more rows */
		lua_pushnil (L);
		return 1;
	} else if (status != OCI_SUCCESS) {
		/* Error */
		return checkerr (L, status, cur->errhp);
	}

	if (lua_istable (L, 2)) {
		int i;
		const char *opts = luaL_optstring (L, 3, "n");
		if (strchr (opts, 'n') != NULL)
			/* Copy values to numerical indices */
			for (i = 1; i <= cur->numcols; i++) {
				int ret = pushvalue (L, cur, i);
				if (ret != 1)
					return ret;
				lua_rawseti (L, 2, i);
			}
		if (strchr (opts, 'a') != NULL)
			/* Copy values to alphanumerical indices */
			for (i = 1; i <= cur->numcols; i++) {
				column_data *col = &(cur->cols[i-1]);
				int ret;
				lua_pushlstring (L, col->name, col->namelen);
				if ((ret = pushvalue (L, cur, i)) != 1)
					return ret;
				lua_rawset (L, 2);
			}
		lua_pushvalue(L, 2);
		return 1; /* return table */
	}
	else {
		int i;
		luaL_checkstack (L, cur->numcols, LUASQL_PREFIX"too many columns");
		for (i = 1; i <= cur->numcols; i++) {
			int ret = pushvalue (L, cur, i);
			if (ret != 1)
				return ret;
		}
		return cur->numcols; /* return #numcols values */
	}
}
コード例 #6
0
ファイル: sm.cpp プロジェクト: 0branch/qtide
// ---------------------------------------------------------------------
string smgetwin1(QWidget *t)
{
  string r;
  if (t==0) {
    r+=spair("text",(string)"");
    r+=spair("select",(string)"");
  } else {
    QTextCursor c=getcursor(t);
    int b=c.selectionStart();
    int e=c.selectionEnd();
    r+=spair("text",getplaintext(t));
    r+=spair("select",QString::number(b)+" "+QString::number(e));
  }
  return r;
}
コード例 #7
0
ファイル: ls_firebird.c プロジェクト: hugohuang1111/moai-dev
/*
** Returns a table of column names from the query
** Lua Returns:
**   a table of column names
**   nil and error message otherwise.
*/
static int cur_colnames (lua_State *L) {
    int i;
    XSQLVAR *var;
    cur_data *cur = getcursor(L,1);

    lua_newtable(L);

    for (i=1, var = cur->out_sqlda->sqlvar; i <= cur->out_sqlda->sqld; i++, var++) {
        lua_pushnumber(L, i);
        lua_pushlstring(L, var->aliasname, var->aliasname_length);
        lua_settable(L, -3);
    }

    return 1;
}
コード例 #8
0
ファイル: ls_oci8.c プロジェクト: Abyss116/luaplus51-all
/*
** Return the list of field names as a table on top of the stack.
*/
static int cur_getcolnames (lua_State *L) {
	cur_data *cur = getcursor (L);
	if (cur->colnames != LUA_NOREF)
		lua_rawgeti (L, LUA_REGISTRYINDEX, cur->colnames);
	else {
		int i;
		lua_newtable (L);
		for (i = 1; i <= cur->numcols; i++) {
			column_data *col = &(cur->cols[i-1]);
			lua_pushlstring (L, col->name, col->namelen);
			lua_rawseti (L, -2, i);
		}
		lua_pushvalue (L, -1);
		cur->colnames = luaL_ref (L, LUA_REGISTRYINDEX);
	}
	return 1;
}
コード例 #9
0
ファイル: ls_odbc.c プロジェクト: LuaDist2/luasql-oci8
/*
** Get another row of the given cursor.
*/
static int cur_fetch (lua_State *L) {
    cur_data *cur = (cur_data *) getcursor (L);
    SQLHSTMT hstmt = cur->hstmt;
    int ret; 
    SQLRETURN rc = SQLFetch(cur->hstmt); 
    if (rc == SQL_NO_DATA) {
        lua_pushnil(L);
        return 1;
    } else if (error(rc)) return fail(L, hSTMT, hstmt);

	if (lua_istable (L, 2)) {
		SQLUSMALLINT i;
		const char *opts = luaL_optstring (L, 3, "n");
		int num = strchr (opts, 'n') != NULL;
		int alpha = strchr (opts, 'a') != NULL;
		for (i = 1; i <= cur->numcols; i++) {
			ret = push_column (L, cur->coltypes, hstmt, i);
			if (ret)
				return ret;
			if (alpha) {
				lua_rawgeti (L, LUA_REGISTRYINDEX, cur->colnames);
				lua_rawgeti (L, -1, i); /* gets column name */
				lua_pushvalue (L, -3); /* duplicates column value */
				lua_rawset (L, 2); /* table[name] = value */
				lua_pop (L, 1);	/* pops colnames table */
			}
			if (num)
				lua_rawseti (L, 2, i);
			else
				lua_pop (L, 1); /* pops value */
		}
		lua_pushvalue (L, 2);
		return 1;	/* return table */
	}
	else {
		SQLUSMALLINT i;
		luaL_checkstack (L, cur->numcols, LUASQL_PREFIX"too many columns");
		for (i = 1; i <= cur->numcols; i++) {
			ret = push_column (L, cur->coltypes, hstmt, i);
			if (ret)
				return ret;
		}
		return cur->numcols;
	}
}
コード例 #10
0
void initcursor(void)
/* Initializes the different cursor types */
{
 struct text_info ti;

 gettextinfo(&ti);
 oldcursor = getcursor();
 if (ti.currmode == MONO)
 {
  shortcursor = 0x0A0C;
  tallcursor = 0x090C;
 }
 else
 {
  shortcursor = 0x0607;
  tallcursor = 0x0507;
 }
} /* initcursor */
コード例 #11
0
ファイル: ttyio.c プロジェクト: sarami55/ng-.1.5
/*
 * This function sets the Ctrl-C check function off.
 * This is called both by ttopen() above and by spawncli() to
 * get the current terminal settings and then change them to what
 * Ng expects.	Thus, stty changes done while spawncli() is in effect
 * will be reflected in Ng.
 */
ttraw() {
	inregs.h.ah = 0x30;		/* Check MS-DOS version.	*/
	intdos(&inregs, &outregs);
	dosversion = outregs.h.al;
	
	if (dosversion > 1) {
		inregs.h.ah = 0x33;	/* Get BREAK check status.	*/
		inregs.h.al = 0x00;
		intdos(&inregs, &outregs);
		breakstat = outregs.h.dl;
		inregs.h.al = 0x01;	/* Set BREAK check status to	*/
		inregs.h.dl = 0x00;	/* no BREAK checking.		*/
		intdos(&inregs, &outregs);
		if (outregs.h.al == 0xff) {
			return(FALSE);
		}

		inregs.h.ah = 0x44;	/* Get IOCTRL status.		*/
		inregs.h.al = 0x00;
		inregs.x.bx = 0x00;	/* 0 = stdin.			*/
		intdos(&inregs, &outregs);
		stdinstat = outregs.h.dl;
		inregs.x.dx = (outregs.x.dx | 0x0020) & 0x0027;	/* raw mode */
		inregs.h.al = 0x01;	/* Set IOCTRL to raw.		*/
		intdos(&inregs, &outregs);
		if (outregs.x.cflag != 0x00) {
			return(FALSE);
		}
	}
	setttysize();
#ifdef	IBMPC	/* 90.02.23  by S.Yoshida */
	assignkey();
	getcursor();	/* 91.01.11  Get cursor info. by S.Yoshida */
#endif	/* IBMPC */
#ifdef	PC9801	/* 90.03.06  by K.Takano */
	assignkey();
	if (use_metakey)
		setezkey();
#endif	/* PC9801 */
	return(TRUE);
}
コード例 #12
0
ファイル: ls_postgres.c プロジェクト: andreasbhansen/luasql
/*
** Get another row of the given cursor.
*/
static int cur_fetch (lua_State *L) {
	cur_data *cur = getcursor (L);
	PGresult *res = cur->pg_res;
	int tuple = cur->curr_tuple;

	if (tuple >= PQntuples(cur->pg_res)) {
		cur_nullify (L, cur);
		lua_pushnil(L);  /* no more results */
		return 1;
	}

	cur->curr_tuple++;
	if (lua_istable (L, 2)) {
		int i;
		const char *opts = luaL_optstring (L, 3, "n");
		if (strchr (opts, 'n') != NULL)
			/* Copy values to numerical indices */
			for (i = 1; i <= cur->numcols; i++) {
				pushvalue (L, res, tuple, i);
				lua_rawseti (L, 2, i);
			}
		if (strchr (opts, 'a') != NULL)
			/* Copy values to alphanumerical indices */
			for (i = 1; i <= cur->numcols; i++) {
				lua_pushstring (L, PQfname (res, i-1));
				pushvalue (L, res, tuple, i);
				lua_rawset (L, 2);
			}
		lua_pushvalue(L, 2);
		return 1; /* return table */
	}
	else {
		int i;
		luaL_checkstack (L, cur->numcols, LUASQL_PREFIX"too many columns");
		for (i = 1; i <= cur->numcols; i++)
			pushvalue (L, res, tuple, i);
		return cur->numcols; /* return #numcols values */
	}
}
コード例 #13
0
ファイル: ls_firebird.c プロジェクト: hugohuang1111/moai-dev
/*
** Returns a row of data from the query
** Lua Returns:
**   list of results or table of results depending on call
**   nil and error message otherwise.
*/
static int cur_fetch (lua_State *L) {
    ISC_STATUS fetch_stat;
    int i;
    cur_data *cur = getcursor(L,1);
    const char *opts = luaL_optstring (L, 3, "n");
    int num = strchr(opts, 'n') != NULL;
    int alpha = strchr(opts, 'a') != NULL;

    if ((fetch_stat = isc_dsql_fetch(cur->env->status_vector, &cur->stmt, 1, cur->out_sqlda)) == 0) {
        if (lua_istable (L, 2)) {
            /* remove the option string */
            lua_settop(L, 2);

            /* loop through the columns */
            for (i = 0; i < cur->out_sqlda->sqld; i++) {
                push_column(L, i, cur);

                if( num ) {
                    lua_pushnumber(L, i+1);
                    lua_pushvalue(L, -2);
                    lua_settable(L, 2);
                }

                if( alpha ) {
                    lua_pushlstring(L, cur->out_sqlda->sqlvar[i].aliasname, cur->out_sqlda->sqlvar[i].aliasname_length);
                    lua_pushvalue(L, -2);
                    lua_settable(L, 2);
                }

                lua_pop(L, 1);
            }

            /* returning given table */
            return 1;
        } else {
            for (i = 0; i < cur->out_sqlda->sqld; i++)
                push_column(L, i, cur);

            /* returning a list of values */
            return cur->out_sqlda->sqld;
        }
    }

    /* isc_dsql_fetch returns 100 if no more rows remain to be retrieved
       so this can be ignored */
    if (fetch_stat != 100L)
        return return_db_error(L, cur->env->status_vector);

    /* last row has been fetched, close cursor */
    isc_dsql_free_statement(cur->env->status_vector, &cur->stmt, DSQL_drop);
    if ( CHECK_DB_ERROR(cur->env->status_vector) )
        return return_db_error(L, cur->env->status_vector);

    /* free the cursor data */
    free_cur(cur);

    cur->closed = 1;

    /* remove cursor from lock count */
    --cur->conn->lock;

    /* return sucsess */
    return 0;
}
コード例 #14
0
ファイル: ls_odbc.c プロジェクト: LuaDist2/luasql-oci8
/*
** Returns the table with column types.
*/
static int cur_coltypes (lua_State *L) {
	cur_data *cur = (cur_data *) getcursor (L);
	lua_rawgeti (L, LUA_REGISTRYINDEX, cur->coltypes);
	return 1;
}
コード例 #15
0
ファイル: ls_mysql.cpp プロジェクト: RayHuo/iASP
/*
** Return the list of field names.
*/
static int cur_getcolnames (lua_State *L) {
	pushtable (L, getcursor(L), colnames);
	return 1;
}
コード例 #16
0
ファイル: ls_sqlite3.c プロジェクト: LuaAV/LuaAV
/*
** Return the list of field names.
*/
static int cur_getcolnames(lua_State *L)
{
    cur_data *cur = getcursor(L);
    lua_rawgeti(L, LUA_REGISTRYINDEX, cur->colnames);
	return 1;
}
コード例 #17
0
ファイル: ls_mysql.cpp プロジェクト: RayHuo/iASP
/*
** Push the number of rows.
*/
static int cur_numrows (lua_State *L) {
	lua_pushnumber (L, (lua_Number)mysql_num_rows (getcursor(L)->my_res));
	return 1;
}
コード例 #18
0
ファイル: ls_postgres.c プロジェクト: andreasbhansen/luasql
/*
** Push the number of rows.
*/
static int cur_numrows (lua_State *L) {
	lua_pushnumber (L, PQntuples (getcursor(L)->pg_res));
	return 1;
}
コード例 #19
0
ファイル: ls_postgres.c プロジェクト: andreasbhansen/luasql
/*
** Return the list of field types.
*/
static int cur_getcoltypes (lua_State *L) {
	pushtable (L, getcursor(L), coltypes, create_coltypes);
	return 1;
}
コード例 #20
0
ファイル: ntk.c プロジェクト: distanceModling/DAKOTA
void
plD_esc_ntk(PLStream *pls, PLINT op, void *ptr)
{
  PLINT i,j;
  short *xa, *ya;
  Pixmap bitmap;
  static unsigned char bit_pat[] = {
    0x24, 0x01, 0x92, 0x00, 0x49, 0x00, 0x24, 0x00, 0x12, 0x00, 0x09, 0x00,
    0x04, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};

  switch (op) {

  case PLESC_DASH:
    xa = (short *) malloc(sizeof(short) * pls->dev_npts);
    ya = (short *) malloc(sizeof(short) * pls->dev_npts);
    for (i = 0; i < pls->dev_npts; i++) {
      xa[i] = pls->dev_x[i];
      ya[i] = pls->dev_y[i];
    }

    j = sprintf(dash, "-dash {");
    for (i = 0; i < pls->nms; i++)
      j += sprintf(&dash[j]," %d %d",
		   (int) ceil(pls->mark[i]/1e3 * ppm),
		   (int) ceil(pls->space[i]/1e3 * ppm));
    sprintf(&dash[j], "}");
    plD_polyline_ntk(pls, xa, ya, pls->dev_npts);
    free(xa); free(ya);
    dash[0] = 0;
    break;

  case PLESC_FLUSH:
    tk_cmd("update");
    break;

  case PLESC_GETC:
    getcursor(pls, (PLGraphicsIn *) ptr);
    break;

  case PLESC_FILL:
    if (pls->patt != 0) {
      /* this is a hack! The real solution is in the if(0) bellow */
      pls->xpmm *= scale;
      pls->ypmm *= scale;
      plfill_soft( pls->dev_x, pls->dev_y, pls->dev_npts);
      pls->xpmm /= scale;
      pls->ypmm /= scale;
    } else {
      j = sprintf(cmd, "$plf.f2.c%d create polygon ", ccanv);
      for (i = 0; i < pls->dev_npts; i++)
	j += sprintf(&cmd[j], "%.1f %.1f ", pls->dev_x[i]/scale,
		     ymax-pls->dev_y[i]/scale);
      j += sprintf(&cmd[j]," -fill %s", curcolor);
      tk_cmd(cmd);
    }

    if (0) {
      if (pls->patt != 0) {
	Tk_DefineBitmap(interp, Tk_GetUid("foo"), bit_pat, 16, 16);
	bitmap = Tk_GetBitmap(interp, mainw, Tk_GetUid("patt"));
      }
      j = sprintf(cmd, "$plf.f2.c%d create polygon ", ccanv);
      for (i = 0; i < pls->dev_npts; i++)
	j += sprintf(&cmd[j], "%.1f %.1f ", pls->dev_x[i]/scale,
		     ymax-pls->dev_y[i]/scale);
      j += sprintf(&cmd[j]," -fill %s", curcolor);
      if (pls->patt != 0)
	sprintf(&cmd[j], " -stipple patt -outline black");

      tk_cmd(cmd);
  /*Tk_FreeBitmap(display, bitmap)*/
    }
    break;
  }
}