当前位置: 首页>>代码示例>>Golang>>正文


Golang Table.Read方法代码示例

本文整理汇总了Golang中github.com/prestonTao/database/table.Table.Read方法的典型用法代码示例。如果您正苦于以下问题:Golang Table.Read方法的具体用法?Golang Table.Read怎么用?Golang Table.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/prestonTao/database/table.Table的用法示例。


在下文中一共展示了Table.Read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Update

func (tr *Transaction) Update(t *table.Table, rowNumber int, row map[string]string) int {
	// Execute "before update" triggers.
	beforeTable, status := tr.DB.Get("~before")
	if status != st.OK {
		return status
	}
	original, status := t.Read(rowNumber)
	if status != st.OK {
		return status
	}
	triggerRA := ra.New()
	_, status = triggerRA.Load(beforeTable)
	if status != st.OK {
		return status
	}
	_, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name)
	if status != st.OK {
		return status
	}
	status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "UP", row, original)
	if status != st.OK {
		return status
	}
	// Update the row.
	status = t.Update(rowNumber, row)
	if status != st.OK {
		return status
	}
	// Execute "after update" triggers.
	afterTable, status := tr.DB.Get("~after")
	if status != st.OK {
		return status
	}
	triggerRA = ra.New()
	_, status = triggerRA.Load(afterTable)
	if status != st.OK {
		return status
	}
	_, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name)
	if status != st.OK {
		return status
	}
	status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "UP", row, original)
	if status != st.OK {
		return status
	}
	// Log the updated row.
	tr.Log(&UndoUpdate{t, rowNumber, original})
	return st.OK
}
开发者ID:shyrobbiani,项目名称:database,代码行数:50,代码来源:update.go

示例2: Delete

func (tr *Transaction) Delete(t *table.Table, rowNumber int) int {
	// Execute "before delete" triggers.
	beforeTable, status := tr.DB.Get("~before")
	if status != st.OK {
		return status
	}
	row, status := t.Read(rowNumber)
	if status != st.OK {
		return status
	}
	triggerRA := ra.New()
	_, status = triggerRA.Load(beforeTable)
	if status != st.OK {
		return status
	}
	_, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name)
	if status != st.OK {
		return status
	}
	status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "DE", row, nil)
	if status != st.OK {
		return status
	}
	// Update the row.
	status = t.Delete(rowNumber)
	if status != st.OK {
		return status
	}
	// Execute "after delete" triggers.
	afterTable, status := tr.DB.Get("~after")
	if status != st.OK {
		return status
	}
	triggerRA = ra.New()
	_, status = triggerRA.Load(afterTable)
	if status != st.OK {
		return status
	}
	_, status = triggerRA.Select("TABLE", filter.Eq{}, t.Name)
	if status != st.OK {
		return status
	}
	status = trigger.ExecuteTrigger(tr.DB, t, triggerRA, "DE", row, nil)
	if status != st.OK {
		return status
	}
	// Log the deleted row.
	tr.Log(&UndoDelete{t, rowNumber})
	return st.OK
}
开发者ID:shyrobbiani,项目名称:database,代码行数:50,代码来源:delete.go

示例3: find

// Look for a value in a table's column, returns true if the value is found.
func find(column, value string, t *table.Table) (bool, int) {
	numberOfRows, status := t.NumberOfRows()
	if status != st.OK {
		return false, status
	}
	for i := 0; i < numberOfRows; i++ {
		row, status := t.Read(i)
		if status != st.OK {
			return false, status
		}
		if row[column] == value {
			return true, st.OK
		}
	}
	return false, st.OK
}
开发者ID:shyrobbiani,项目名称:database,代码行数:17,代码来源:constraint.go

示例4: NLJoin

// Relational algebra join using nested loops.
func (r *Result) NLJoin(alias string, t2 *table.Table, name string) (*Result, int) {
	// t1 is the table in RA result.
	t1Column := r.Aliases[alias].ColumnName
	t1 := r.Tables[r.Aliases[alias].TableName]
	t2RowNumbers := make([]int, 0)
	// t2 is the external table.
	t2NumberOfRows, status := t2.NumberOfRows()
	if status != st.OK {
		return r, status
	}
	// Prepare to re-arrange the sequence of row numbers of all existing tables in RA result.
	newRowNumbers := make(map[string][]int)
	for name, _ := range r.Tables {
		newRowNumbers[name] = make([]int, 0)
	}
	// NL begins.
	for i, t1RowNumber := range t1.RowNumbers {
		for t2RowNumber := 0; t2RowNumber < t2NumberOfRows; t2RowNumber++ {
			t1Row, status := t1.Table.Read(t1RowNumber)
			if status != st.OK {
				return r, status
			}
			t2Row, status := t2.Read(t2RowNumber)
			if status != st.OK {
				return r, status
			}
			if t1Row["~del"] != "y" && t2Row["~del"] != "y" && t1Row[t1Column] == t2Row[name] {
				for name, _ := range newRowNumbers {
					newRowNumbers[name] = append(newRowNumbers[name][:], r.Tables[name].RowNumbers[i])
				}
				t2RowNumbers = append(t2RowNumbers[:], t2RowNumber)
			}
		}
	}
	// Re-arrange the sequence of row numbers of all existing tables in RA result.
	for name, rowNumbers := range newRowNumbers {
		r.Tables[name].RowNumbers = rowNumbers
	}
	// Load columns of t2 into RA result.
	r.Load(t2)
	t2Table := r.Tables[t2.Name]
	t2Table.RowNumbers = t2RowNumbers
	return r, st.OK
}
开发者ID:shyrobbiani,项目名称:database,代码行数:45,代码来源:nl_join.go


注:本文中的github.com/prestonTao/database/table.Table.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。